【发布时间】:2011-03-09 08:40:02
【问题描述】:
所以我通过根据需要插入/删除/重新加载行来更新 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 重置为工作状态?
【问题讨论】:
标签: iphone cocoa-touch uitableview uikit