Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

CellForRowatIndexPath not executing?

I've set up a breakpoint at the beginning of the following delegate method.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
}

when i run my application (simulator or device), the breakpoint does not execute.

I have the dataSource and Delegate protocols passed into the header, but my tableView cells remain nil simply because I'm executing my code in this delegation method.

Since the method is not executing or halting to any breakpoints, what could be the root of this problem.

The breakpoint works in my other applications, but I cant seem to figure whats causing the method to hide its self sort of speak.

Hey Rashii the same thing happened to me not long ago, make sure that you are implementing the rest of methods for the delegate, namely tableView:numberOfRowsInSection, I battled with that for a while until I implemented the rest of methods, once I did I was able to see my code being called

I have all of my delegate messages implemented.

Silly question Rashii, you did wire your class to the storyboard right ?

Yes I have it properly connected in Interface Builder.

3 Answers

Hey Rashii : Several steps to help you locating the problem. 1 Make sure your ViewController linked to your xib file or storyboard, you can check it by add a breakpoint to viewDidLoad method. 2 Make sure you'd set your ViewController to be the datasource and delegate of the tableView (seem you already did it). 3 Be sure you had implemented the delegate method

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex and return a correct number which is not ZERO. Usually you can return your dataArray's count here. 4 If you change your DataArray dynamically, remember to invoke reloadData method.

Hope these can help you.

Thank you Hector, i implemented my delegate methods and i saw that

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex 
{

return 0;
}

was returning 0. I changed this to 1. Everything works fine.

So happy that I can help~

Hello Rashii. Is that your unique breakpoint? maybe you have more than one breakpoint and the compiler is stopping before it reaches cellForRowAtIndexPath

Yes it is the only one.

Could you share the project so I can try to reproduce here?

Im sorry i cant release this project as open source.

Although i can post code snippets if you'd like.