简体   繁体   中英

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.

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).

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)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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