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
Rashii Henry
16,433 PointsCellForRowatIndexPath 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.
Rashii Henry
16,433 PointsI have all of my delegate messages implemented.
Leo Picado
9,182 PointsSilly question Rashii, you did wire your class to the storyboard right ?
Rashii Henry
16,433 PointsYes I have it properly connected in Interface Builder.
3 Answers
Tiger Wang
26,548 PointsHey 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.
Rashii Henry
16,433 PointsThank 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.
Tiger Wang
26,548 PointsSo happy that I can help~
Emilio Arcioni
6,040 PointsHello Rashii. Is that your unique breakpoint? maybe you have more than one breakpoint and the compiler is stopping before it reaches cellForRowAtIndexPath
Rashii Henry
16,433 PointsYes it is the only one.
Fernando Fernandes
4,154 PointsCould you share the project so I can try to reproduce here?
Rashii Henry
16,433 PointsIm sorry i cant release this project as open source.
Although i can post code snippets if you'd like.
Leo Picado
9,182 PointsLeo Picado
9,182 PointsHey 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