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?
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:
This post mentions some of the other, more complex, customisable options like Grand Central Dispatch and NSThread.