Reputation: 2819
I have an iPad application that is being backed by Core Date and displaying data in a UITableView. I am also using custom cells to display multiple ULabels per cell.
It works fine but when a lot of items are added to the tableView it bogs down and feels kind of sluggish. I am not currently using the NSFetchedResultsController. Whenever a change is made to the data, an ivar array's data is refreshed like this:
items = [self.managedObjectContext executeFetchRequest:allItems error:&error];
Items is the array the tableView pulls all of its data from and everything updates and works. But it isn't super fast! Is there a problem with my approach? Is the NSFetchedResultsController the only way to go? The processing going on in the delegate/data source methods isn't that heavy. Basically pulling out values from the array and setting them to UILabels.
Everything works the way I need it to right now, I just need it to be more responsive.
Thanks
Upvotes: 0
Views: 299
Reputation: 28409
Use Instruments. Always. Forever.
Most likely, you need to at least mimic some of the batching and forward-thinking that FRC does. However, you may find that you are always accessing relationships, and pre-fetching them may solve your problem.
Everything is pure speculation without hard, cold, numbers... which you can easily get from Instruments.
EDIT
Cell drawing could slow you down. However, that would be observable with a smaller number of objects as well. You would usually only see performance slow down due to drawing if your data is dramatically different with the other cells.
Now, that, of course, assumes you are using cell reuse. If you are not reusing your cells, then all bets are off. However, with cell reuse, you should not typically see performance relative to the number of objects.
Again, run instruments. It's the only way to know where your issues lie. Everything else is a waste of time.
Upvotes: 3
Reputation: 80265
NSFetchedResultsController
is definitely highly recommended. It could not only potentially address your performance problem, but will also lead to all kinds of convenient facilities (such as the delegate protocol) and behind the scenes optimizations.
The most important of these optimizations would perhaps be memory management. Your solution (with all items in an array) appears to be a poor design choice and will not scale to a large amount of records / rows.
That being said, use the usual optimization strategies when drawing cells:
If performance is still an issue, you will have to draw your content yourself by overriding the drawRect
of UITableViewCell
subclass.
Upvotes: 1