Reputation: 1393
I need implement some kind of lazy loading in my UITableView.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//... some initializations here
//this is a function that pulls my cell data using helper class
NSData *cellData=[MyDataClass dataForCellAtIndexPath:indexpath.row];
//... here I populate pulled data to cell
return cell;
}
Everything works great, but table view scrolls not smoothly, because dataForCellAtIndexPath
method is slow. So I need to implement lazy populating data into cells by calling this method. The result I expect is that table view will scroll smoothly but cell's content will populate a bit after the cell is drawn. Help me please, How can it be done?
Upvotes: 5
Views: 3679
Reputation: 1658
for that u can load your new data on the basis of index value of table cells
you can put condition for how much new data you want to load because its depends on which cell s are currently examine by the users.
Upvotes: -1
Reputation: 523
Yes, you could look at pushing your data collection onto a background thread. The first thing to try is the simplest option to see if it improves anything:
[MyDataClass performSelectorInBackground:@selector(dataForCellAtIndexPath:) withObject:indexpath.row];
This post mentions some of the other, more complex, customisable options like Grand Central Dispatch and NSThread.
Upvotes: 4
Reputation: 12325
If you are using a large amount of data, I would suggest saving them onto Core-data
and/or use NSFetchedResultsController
to populate your tableView.
It has been created & tied up with your tableView mainly to populate your tableView faster and have high performance.
Here is the link to the documentation of NSFetchedResultsController !
Upvotes: 2