tableView(_:numberOfRowsInSection:) called for all sections

Hello,


I have a UITableView displaying a data set that is sectioned by date. Since the data span across a few years there are thousands of sections. When showing the data using NSFetchedResultsController, I noticed that tableView( _:numberOfRowsInSection: ) was called for all sections multiple times. This has slowed down the app significantly.


Is there a workaround for this problem?


Thanks!

Are you doing computation in numberOfRowsInSection or how do you know it is slowing things down?

You say you have thousands of sections. Is it feasible for the user to scroll to the end of the table? If not, is it really necessary to have everything all in one table? Perhaps you might want to subdivide it some other way, by month or something.

In numberOfRowsInSection I'm just calling fetchedResultsController.sections[section].numberOfObjects. Nothing else. I used the Time Profiler Instrument to pinpoint to that method.

It is very possible that the user will want to scroll to the bottom of the table. I'm reluctant to change the way data are displayed right now.

* You might want to ask this question in the Core Data forum.

* You might want to investigate the countForFetchRequest API.

* You might want to save the counts in a separate table/Entity in your Core Data model. I assume that the data for the older dates never changes.

tableView(_:numberOfRowsInSection:) called for all sections
 
 
Q