Reputation: 77596
I have lots of data and lots of rows in my tableView. when data changes I want to update my visible cells on the screen, I really don't want to use reloadData because it's an expensive call.
Is it possible to somehow update the visible cells only?
I tried calling : beginUpdate
& endUpdate
on the table, but that doesn't work all the time?
Any suggestions?
Upvotes: 36
Views: 25097
Reputation: 16022
For Swift 3:
tableView.reloadRows(at: tableView.indexPathsForVisibleRows!, with: .none)
Upvotes: 0
Reputation: 107
Try calling 'deleteRowsAtIndexPaths', a method of UITableView, right after you delete the model from your data source. For example, if you are deleting a row in editing mode, you could write something like the code below. Note that the first line in the 'if' statement removes the object from the data source, and the second line cleans up the table:
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ( editingStyle == UITableViewCellEditingStyleDelete ) {
[[[[[ItemsStore sharedStore] parameterArray] objectAtIndex:indexPath.section] objectForKey:@"data"] removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Upvotes: -1
Reputation: 17906
You can:
[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows]
withRowAnimation:UITableViewRowAnimationNone];
Upvotes: 87