Dav*_*Liu 13 iphone cocoa-touch uitableview uikit
所以我通过插入/删除/重新加载行来更新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;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,一旦它遇到该异常,reloadData似乎无法正常工作.有没有其他方法可以将UITableView基本上重置为工作状态?
更理想的情况是,您应该使用一个数组来支持表,该数组保证能够执行表期望的操作。UIKit 期望异常是致命的(这符合 Apple 的理念,即异常表明程序员错误。)
| 归档时间: |
|
| 查看次数: |
2910 次 |
| 最近记录: |