So I'm updating a tableview by inserting/deleting/reloading rows as needed, but, as I'm not 100% confident that the tableview will always update correctly, is there any way to fail safely from a bad batch of updates?
Right now, I have this:
// Try to animate the updates. If something goes wrong, just reloadData.
@try {
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:deleteArray withRowAnimation:UITableViewRowAnimationMiddle];
[tableView reloadRowsAtIndexPaths:reloadArray withRowAnimation:UITableViewRowAnimationNone];
[tableView insertRowsAtIndexPaths:insertArray withRowAnimation:UITableViewRowAnimationMiddle];
[tableView endUpdates];
}
@catch (NSException * e) {
if([[e name] isEqualToString:NSInternalInconsistencyException]){
[tableView reloadData];
NSLog(@"animation failed, just reloading data");
}
else {
@throw e;
}
}
However, once it hits that exception, reloadData seems to not work. Is there any other way to basically reset the UITableView into a working state?
More ideally you should be backing the table with an array that's guaranteed to do what the table expects it to do. UIKit expects exceptions to be fatal (this holds with Apple's philosophy that exceptions indicate programmer error.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With