[英]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;
}
这段代码在iOS9中甚至还不错,在iOS10中崩溃了,但是在调试代码时却没有出现。
崩溃信息:
更新无效:部分0中的行数无效。更新(7)之后,现有部分中包含的行数必须等于更新(0)之前该部分中包含的行数,再加上或减去该数字从该部分插入或删除的行数(插入1,删除0),加上或减去移入或移出该部分的行数(移入0,移出0)。
您需要根据以下内容进行更改:
至
[self.table reloadData];
从
[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.