有人可以建议我的代码有什么问题吗.....

self.modleClass.foldersAray有一个对象,tableview有一个部分,一行

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (editingStyle == UITableViewCellEditingStyleDelete) {

        // Delete the row from the data source
        [self.tableview setEditing:YES animated:YES];

        [self.modleClass.foldersAray removeObjectAtIndex:indexPath.row];

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YEs];

        [tableView reloadData];
   }
}

我收到如下错误。
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), 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).'

最佳答案

这样吧

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

      if (editingStyle == UITableViewCellEditingStyleDelete) {

          [self.modleClass.foldersAray removeObjectAtIndex:indexPath.row];

          [tableView reloadData];
      }
}

够了............

关于iphone - 如何在表格 View 中删除单元格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15023979/

10-10 09:02