2

我在一个应用程序中有几个 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

在崩溃之前既不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;
    }
}

更新:这实际上是一个大问题,因为当 tableview 滚动时应用程序几乎无法使用。

4

2 回答 2

11

看起来这种情况的根本原因是在刷新时尝试重新加载表视图中的行。一定是某种不一致的状态导致了应用程序每次崩溃。

于 2012-03-25T17:14:10.733 回答
0

解决方案:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
//    tableView.isEditing ? NSLog(@"show edit controls"):NSLog(@"don't show edit controls");

    if(tableView.isEditing){
        return NO;
    }else{
        return YES;
    }
}
于 2015-03-16T12:26:26.047 回答