UITableView numberOfRowsInSection is called multiple times

How many times should the tableView:numberOfRowsInSection method be called when the table view is populated?

My application crashes without warnings, errors or stack tracing. I also tested memory leaks and did not find any. The application is supported at around 1.4 MB.

I have an NSLog report as methods are passed by message, and I notice that tableView:numberOfRowsInSection is called several times. The app crashes during one of these โ€œextraโ€ calls. The point at which the application crashes changes. I should indicate that the table fills in about 600 cells, if that matters.

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

+7
source share
3 answers

See my answer in another similar question: link
Basically, table view delegate method calls can be triggered by various events. It would not be a surprise for me that a UITableView calls numberOfRowsInSection several times (even for the same section).

+1
source

the best way is to use Download lazy downloadable table . so 600 cells are a big sum, and if you call all the data in one go, they will always be broken due to memory problems.

try using the provided code.

Another answer at https://stackoverflow.com/a/3/9/28/28 may help you.

0
source

I ran into the same problem, the first instance of tableview is not nil, and in subsequent times it is zero. The problem was that I had not yet set the return value for the table tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath and because of this continued. As soon as I set the return value, the problem disappeared. Hope this helps someone.

0
source

All Articles