A view controller has a data model which updates constantly and aggressively
A UItableview (storyTable) is called ever so often to update and reflect the changes to date.
(Changed the code to reflect only a single beginUpdates endUpdates) - still crashes
[self.storyTable beginUpdates];
if([deleteIndexPaths count]){
DLog(@"Table refresh delele rows :%@",deleteIndexPaths);
[self.storyTable deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationNone];
}
if ([addIndexPaths count]){
DLog(@"Table refresh add rows :%@",addIndexPaths);
[self.storyTable insertRowsAtIndexPaths:addIndexPaths withRowAnimation:UITableViewRowAnimationTop];
}
if ([changedIndexPaths count]){
DLog(@"Table refresh change rows :%@",changedIndexPaths);
[self.storyTable reloadRowsAtIndexPaths:changedIndexPaths withRowAnimation:UITableViewRowAnimationFade ];
}
[self.storyTable endUpdates];
//[self.storyTable endUpdates];
tableIsAnimating = NO;
}
Crashes from time to time with the following message: (mostly on deleteRowsAtIndexPaths...)
* Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-2380.17/UITableView.m:1070
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (20) must be equal to the number of rows contained in that section before the update (20), plus or minus the number of rows inserted or deleted from that section (0 inserted, 10 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
or :
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 20 into section 0, but there are only 20 rows in section 0 after the update'
Question: How can one add some protective code to prevent the crash?
NSFetchedResultsController
andNSFetchedResultsControllerDelegate
to show the model changes? Are you not using Core Data? – Gobot