简体   繁体   English

当我调用[tableView insertRowsAtIndexPaths:withRowAnimation:]时,在iOS10中崩溃

[英]When I called [tableView insertRowsAtIndexPaths: withRowAnimation:], crashed in iOS10

- (void)registerCellCallBack:(id<CellCallBack>)callBack {
    int i = 0;
    for(; i < _dataSource.count; ++i) {
        id<CellCallBack> oldCallBack = _dataSource[i];
        if([callBack key] <= [oldCallBack key]) {
            break;
        }
    }
    if(i < _dataSource.count) {
        [_dataSource insertObject:callBack atIndex:i];
    } else {
        [_dataSource addObject:callBack];
    }

    [self.table beginUpdates];
    [self.table insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
    [self.table endUpdates]; //--crashed here called "NSInternalInconsistencyException(SIGABRT)"
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataSource.count;
}

The code which even was well in iOS9, crashed in iOS10, but not appear when I debug my code. 这段代码在iOS9中甚至还不错,在iOS10中崩溃了,但是在调试代码时却没有出现。

Crash info: 崩溃信息:

Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (7) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). 更新无效:部分0中的行数无效。更新(7)之后,现有部分中包含的行数必须等于更新(0)之前该部分中包含的行数,再加上或减去该数字从该部分插入或删除的行数(插入1,删除0),加上或减去移入或移出该部分的行数(移入0,移出0)。

You need to change as per below: 您需要根据以下内容进行更改:

To

 [self.table reloadData];

From

 [self.table beginUpdates];
 [self.table insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:i inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
 [self.table endUpdates]; //--crashed here called "NSInternalInconsistencyException(SIGABRT)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM