Reputation: 35
I have a lot of cells (around 3000 cells) that I need to reload constantly. I was wondering if there is currently a way to reload it faster without it lagging the App. I do the typical [tableview reloadData];
Any tips or suggestions are appreciated.
Upvotes: 0
Views: 1072
Reputation: 510
When making a reloadData for your tableView, tableView:heightForRow: delegate function make a height recalculation of every row.
My solution is to save the heights for your cells already calculated (create an NSDictionary that contains all row heights. exp. create a NSDictionary with keys is the id of object that will be show on the cell and the value is the height).
When tableView attempt to recalculate the height of each cell, it will check if we have already a saved entry in your dictionary with this key (id of object), and tableView:heightForRow: will return this value if found. I am using this solution in my chat app, and I noticed a performance increase. Good luck.
Upvotes: 0
Reputation: 11725
Since you have not provided context or code to show where you call [tableview reloadData];
, I can only talk in generalities.
I am going to assume in your 3,000 rows possible 20 are displayed at a time.
Here is the sequence of events or actions that needs to occurs
indexPathForVisibleRows
If row is visible, then following actions should be taken
[tableview beginUpdates]
[tableview reloadRowsAtIndexPaths...]
[tableview endUpdates]
Upvotes: 1
Reputation: 12260
Reload only visible cells if you have consistent number of items, otherwise use insert/delete methods to add cells to tableview.
Upvotes: 0
Reputation: 7734
Don't implement tableView:heightForRow: in your delegate or it will slow down considerably as it recalculates every row. iOS checks to see if you implement that method and if you define it the OS changes its table height calculation from a simple multiply to a loop over the cells.
Upvotes: 2