Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView numberOfRowsInSection called multiple times

How many times should the tableView:numberOfRowsInSection method be called when populating a table view?

My application is crashing with no warnings, errors, or a stack trace. I have also tested for memory leaks and have found none. The app holds steady at about 1.4MB.

I have NSLog reporting as methods are messaged, and I notice that tableView:numberOfRowsInSection is being called multiple times. The app crashes during one of these "extra" calls. The point at which the app crashes varies. I should point out that the table is populating about 600 cells, if that makes a difference.

I can post code if you want, but my data source comes from a singleton class, so It is a lot of code. Any help would be greatly appreciated.

like image 844
Chris Avatar asked Mar 08 '11 09:03

Chris


2 Answers

See my answer in another similar question: link
Basically, calls to the the delegate methods of a table view can be triggered by different events. It wouldn't be a suprise to me that UITableView calls numberOfRowsInSection multiple times (even for the same section).

like image 64
Andrei Stanescu Avatar answered Oct 12 '22 23:10

Andrei Stanescu


I faced the same problem, the first time tableview instance is not nil and the subsequent times it is nil. The problem was, I had yet not set the return value for

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 

and because of this it kept happening. Once I set a return value the problem was gone. Hope this helps someone.

like image 39
Omar Avatar answered Oct 13 '22 00:10

Omar