UITableView:在更新错误后从NSInternalInconsistencyException恢复?

时间:2010-06-28 21:47:56

标签: 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;
        }
    }

但是,一旦遇到该异常,reloadData似乎无效。有没有其他方法可以将UITableView基本上重置为工作状态?

1 个答案:

答案 0 :(得分:3)

理想情况下,您应该使用一个数组来支持该表,该数组可以保证执行表所期望的操作。 UIKit期望异常是致命的(这与Apple的理念一致,即异常表明程序员错误。)