iOS Invalid update: invalid number of rows in section 0. The number of rows contained in an exi...

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

下面是网友遇到一种情况,改成先删除Model , 再更新就好了

// Editing of rows is enabled
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //when delete is tapped
        [currentCart removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}
  • Invalid update: invalid number of rows in section 0

不过此处我们遇到的一个 BUG 是在 iOS 11 上,在我们所有用户中一个月才发生一次奔溃

 [self.tableView beginUpdates];
 [self.tableView endUpdates];

当然此处直接替换成

[self.tableView reloadData];

当然这样毕竟多走了一些不必要的流程,如何在不耗流程下解决这个崩溃呢?
暂时没有重现,持续观察中。。。

你可能感兴趣的:(iOS Invalid update: invalid number of rows in section 0. The number of rows contained in an exi...)