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

标签 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 重置为工作状态?

最佳答案

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

关于iphone - UITableView:在错误更新后从 NSInternalInconsistencyException 中恢复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3136391/

相关文章:

ios - 当在 Objective-C 中的搜索栏内按下时,UISearchController 会触摸到安全区域

iPhone 应用程序因未知错误而崩溃

iphone - iOS从 View Controller 访问 View 的变量

objective-c - NSInvocation 是否保留 self、_cmd 和分配的参数?

iphone - 读取静态库中的.pch文件

ios - 自定义 UITableviewCell 中的多行标签

swift - 在表格 View 单元格中键入时键盘会覆盖 TextView

iPhone iOS UIFont 转换为 CTFontRef 导致尺寸未对齐

iphone - 向现有 Xcode 项目本地化添加新语言

iphone - ipAd 不适合 iPad 横向模式