开发者

UITableView: Recovering from NSInternalInconsistencyException after bad updates?

So I'm updating a tableview by inserting/deleting/reloading rows as ne开发者_如何学JAVAeded, but, as I'm not 100% confident that the tableview will always update correctly, is there any way to fail safely from a bad batch of updates?

Right now, I have this:

    // 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;
        }
    }

However, once it hits that exception, reloadData seems to not work. Is there any other way to basically reset the UITableView into a working state?


More ideally you should be backing the table with an array that's guaranteed to do what the table expects it to do. UIKit expects exceptions to be fatal (this holds with Apple's philosophy that exceptions indicate programmer error.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜