10
votes

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.

3
can u pls post the code?PgmFreek

3 Answers

1
votes

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).

1
votes

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.

0
votes

the best way is to use Lazy table image loading . so that the 600 cells is a big amount and if you call all the data in a single time it will always going to be crashed due to memory issues.

try using the code I provided .

Another answer on the stackoverflow can help you out.