Ios 删除表单元格会导致崩溃

Ios 删除表单元格会导致崩溃,ios,objective-c,uitableview,Ios,Objective C,Uitableview,使用deleteRowsAtIndexPaths删除表格单元格时,如果尝试使用滑动手势删除单元格以进入编辑模式,然后单击delete,则会发生崩溃。如果通过切换“编辑/完成”按钮进入编辑模式,则删除单元格表将正常更新,不会出现问题 我也尝试过使用[table beginUpdates]和[table endUpdates],但也没有成功。 另外,[table reloadData]在这两种情况下都有效 正如您所看到的,我已经尝试了使用RowAnimation:UITableViewRowAnim

使用deleteRowsAtIndexPaths删除表格单元格时,如果尝试使用滑动手势删除单元格以进入编辑模式,然后单击delete,则会发生崩溃。如果通过切换“编辑/完成”按钮进入编辑模式,则删除单元格表将正常更新,不会出现问题

我也尝试过使用
[table beginUpdates]
[table endUpdates]
,但也没有成功。 另外,
[table reloadData]
在这两种情况下都有效 正如您所看到的,我已经尝试了使用RowAnimation:UITableViewRowAnimationFade的[table reloadSections:[NSIndexSet indexSetWithIndex:IndexXPath.section]会发生相同的崩溃

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if (editingStyle == UITableViewCellEditingStyleDelete) 
    {
        NSMutableArray *temp = nil;
        switch (indexPath.section)
        {
            case 0:
            {
                temp = self.entireSavedArray;
                break;
            }
            case 1:
            {
                temp = self.entireSavedArray2014;
                break;
            }
            case 2:
            {
                temp = self.entireSavedArray2013;
                break;
            }
            case 3:
            {
                temp = self.entireSavedArray2012;
                break;
            } 
            case 4:
            {
                temp = self.entireSavedArray2011;
                break;
            }          
            case 5:
            {
                temp = self.entireSavedArray2010;
                break;
            }
            default:
                break;
        }
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];
        [temp removeObjectAtIndex: ((int)indexPath.row * 11)];

        [self.table deleteRowsAtIndexPaths: [NSArray arrayWithObjects: indexPath, nil] withRowAnimation: UITableViewRowAnimationFade];
        //[tableView reloadSections:[NSIndexSet indexSetWithIndex: indexPath.section] withRowAnimation: UITableViewRowAnimationFade];
    }
}

当我删除一行时,使用上面的代码对我很有效。

问题在于,刷卡手势将表格置于编辑模式,而无需点击编辑/完成按钮。这通常不会是一个问题,但是当表格未处于编辑模式时,我将占位符单元格添加到表格中,然后在按下“完成”按钮时将其添加回。(我改变了我的数据模型)最初创建应用程序时,我通过点击编辑/完成按钮进行调整解决了这个问题

解决方案:由于刷卡手势进入编辑模式而无需点击编辑/完成按钮,因此我需要以另一种方式进行调整。我是通过以下方式做到这一点的:

- (void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self makeAdjustments];
}
并在这里作出调整:

- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self makeAdjustments];
}

发布完整的错误消息。如果可以了解代码的头尾,这会有所帮助。注释会很有用。用户滑动以删除表中的一行。然后从数据源阵列中删除11个对象。然后告诉表删除1行。这不符合逻辑。您的
numberOfRowsInSection:
方法很可能不匹配。我必须为我写得不好的代码道歉。我在2009年学习面向对象编程时创建了这个应用程序。不幸的是,我现在必须忍受我糟糕的设计选择。数组中的每11项包含一个单元格的数据。我相当肯定数据匹配正确-因为使用“编辑/完成”按钮的证据可以毫无问题地工作-与使用持续导致异常的滑动手势相比。错误是:**断言失败在-[UITableView\u endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1070I在使用“刷卡删除”与使用“编辑/完成”按钮进入编辑模式时发现了一个明确的问题。检查numberOfRowsInSection方法时:每个部分报告正确的行数,并且在为最终部分调用该方法之前,即使编辑部分是第一部分。
- (void)tableView:(UITableView*)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath{
[self makeAdjustments];
}