I have a table view with more than 1000 cells (I display about 10 on the screen). Following a "filter" action by the user I want to remove about 80% of them, then after a second filter another 80%. When working with 100 cells it's roughly instantaneous but with a 1000 it takes 0.5 seconds to finish the method [tableView endUpdates] and this totally destroys the user experience.
I create the array of Index Paths like this:
for (int i=1; i<[appDelegate.myArray count]; i++) { //more than 1000 objects in myArray
if (![[appDelegate.myArray objectAtIndex:i] myTest]) { //myTest returns a BOOL
[appDelegate.rowsToDelete addObject:[NSIndexPath xxxxx]]; //the index path of the object that just failed the test and must be removed];
}
}
[self.myTableViewController.tableView deleteRowsAtIndexPaths:appDelegate.rowsToDelete withRowAnimation:UITableViewRowAnimationRight];
I have tried 2 solutions, one is threading so that my user can see other parts of the UI moving whist the tableView is updating. But if he launches another level of filtering this often results in the long wait if not a crash.
I have also tried to remove the first few cells (those on the screen) and then just remove the other objects that have failed the test from the datasource without removing their corresponding cells from the tableView as they are out of sight. This gives the good, rapid result, but I then get problems with the number of rows such as:
'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (94) must be equal to the number of rows contained in that section before the update (927), plus or minus the number of rows inserted or deleted from that section (0 inserted, 215 deleted).'
Has anybody had such a performance issue? ways to solve it? Cheers, CD