滑动删除时崩溃

Ech*_*lon 2 iphone uitableview ios swipe-gesture

我在一个应用程序中有几个UITableViews,并且滑动删除在所有这些都正常工作.问题是,当我尝试滑过空单元格(在底部)时,应用程序崩溃了:

 *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit/UIKit-1914.84/UITableView.m:833
2012-03-24 16:20:03.158 [22339:707] Exception - attempt to delete row 3 from section 0 which only contains 3 rows before the update - attempt to delete row 3 from section 0 which only contains 3 rows before the update
Run Code Online (Sandbox Code Playgroud)

在崩溃之前既cellForRowAtIndexPath, commitEditingStyle没有editingStyleForRowAtIndexPath调用也没有被调用,就像崩溃发生在我的任何方法都有机会被调用之前.

作为参考,我有这个 editingStyleForRowAtIndexPath

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ((indexPath.row == self.insertIndex && indexPath.section == [self.sections count] -1) || (indexPath.row == 0 && [sections count]==0)) { // last row of section, or only row of only section
        return UITableViewCellEditingStyleInsert;
    } else {
        return UITableViewCellEditingStyleDelete;
    }
}
Run Code Online (Sandbox Code Playgroud)

更新:这实际上是一个巨大的问题,因为桌面滚动时应用程序几乎无法使用.

Ech*_*lon 11

看起来这样做的根本原因是在刷新时尝试在表视图中重新加载行.必定会出现某种不一致的状态,每次都会导致应用程序崩溃.