Ios 从tableview中删除一行是否导致崩溃?

Ios 从tableview中删除一行是否导致崩溃?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个从数组加载数据的tableview,名为self.data。 然后我尝试删除一行,因此首先我将其从数据数组中删除,然后我尝试使用以下方法将其从表视图中删除: Data *d=[[Data alloc] init]; [d removeObject:ID]; NSLog(@"%ld",editingRow); //the right row to remove NSIndexPath *indexPath = [NSIndexPath indexPathFor

我有一个从数组加载数据的tableview,名为
self.data
。 然后我尝试删除一行,因此首先我将其从数据数组中删除,然后我尝试使用以下方法将其从表视图中删除:

 Data *d=[[Data alloc] init];
    [d removeObject:ID];

    NSLog(@"%ld",editingRow); //the right row to remove

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:editingRow inSection:0];


     //update table
     [self.tableView beginUpdates];
      [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
     [self.tableView endUpdates];
坠机原因如下:

Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

TableViewDelegate

    [self.tableView beginUpdates];

    [d removeObject:ID];

    [self.tableView deleteRowsAtIndexPaths:[NSIndexPath indexPathForRow:ID inSection:0]
                  withRowAnimation:UITableViewRowAnimationRight];

    [self.tableView endUpdates];

谢谢这和我做的完全一样。我看不出这个答案带来了什么新东西。您删除了ID为的对象,但必须根据indexPath.row.Error删除。我正在删除ID为的对象,因为数据库顺序与tableview顺序不同。此外,删除哪一行并不重要,但db中的行数应该是-1。好的,我理解,从idy中删除对象很好,您必须传递ID的indexPath.row。