我在向 tableview 插入一行时遇到崩溃问题。当分页重新加载(tableview 的非常快速滚动)表视图和插入广告行的时间几乎相似时,就会发生这种情况。
广告插入方式
[self.news insertObject:adStory atIndex:index];
NSArray *paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:index inSection:0]];
[[self tableView] beginUpdates];
[[self tableView] insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
[[self tableView] endUpdates];
操作Didfinish
[_tableView relaoddata];
崩溃日志
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:第 0 节中的行数无效。更新后现有节中包含的行数 (45) 必须等于行数更新前包含在该部分中 (43),加上或减去从该部分插入或删除的行数(插入 1,删除 0),加上或减去移入或移出该部分的行数(0 移入, 0 移出).'
*** First throw call stack:
(0 CoreFoundation 0x000000010e8ebb0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010e357141 objc_exception_throw + 48
2 CoreFoundation 0x000000010e8efcf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00000001088413b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x000000010c8d78e8 -[UITableView _endCellAnimationsWithContext:] + 16362
5 UIKit 0x000000010c8ee9cc -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 329
请确保在委托方法返回的行数- (NSInteger)numberOfRowsInSection:(NSInteger)section;
等同于的,以后你insertRowsAtIndexPaths
和endUpdates
。例如,如果较早的 numberOfRows 是 4 并且您插入一行,则 numberOfRows 应返回 4+1。否则它将在 endUpdate 中不匹配。
以下崩溃日志仅描述了这一点。
*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无效更新:第 0 节中的行数无效。更新后现有节中包含的行数 (45) 必须等于行数更新前包含在该部分中 (43),加上或减去从该部分插入或删除的行数(插入 1,删除 0),加上或减去移入或移出该部分的行数(0 移入, 0 移出).'
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句