简体   繁体   中英

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.

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM