因此,我通过根据需要插入/删除/重新加载行来更新 TableView ,但是,由于我不是 100% 确信 TableView 将始终正确更新,因此有什么方法可以从一批错误的行中安全地失败更新?
现在,我有这个:
// 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;
}
}
但是,一旦遇到异常,reloadData 似乎就不起作用了。有没有其他方法可以将 UITableView 重置为工作状态?
最佳答案
更理想的情况是,您应该使用一个数组来支持表,该数组保证能够执行表期望的操作。 UIKit 期望异常是致命的(这符合 Apple 的理念,即异常表明程序员错误。)
关于iphone - UITableView:在错误更新后从 NSInternalInconsistencyException 中恢复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3136391/