开发者

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开发者_JS百科 be greatly appreciated.


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜