【发布时间】:2012-04-03 05:14:15
【问题描述】:
我在使用 insertRowsAtIndexPaths: 时遇到问题。我不太确定它是如何工作的。我观看了关于它的 WWDC 2010 视频,但我仍然收到错误消息。我以为我应该更新模型,然后将 insertRowsAtIndexPaths: 包装在 tableView beginUpdates 和 endUpdates 调用中。我有的是这样的:
self.customTableArray = (NSMutableArray *)sortedArray;
[_customTableView beginUpdates];
[tempUnsortedArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
[sortedArray enumerateObjectsUsingBlock:^(id sortedObj, NSUInteger sortedIdx, BOOL *sortedStop) {
if ([obj isEqualToString:sortedObj]) {
NSIndexPath *newRow = [NSIndexPath indexPathForRow:sortedIdx inSection:0];
[_customTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newRow] withRowAnimation:UITableViewRowAnimationAutomatic];
*sortedStop = YES;
}
}];
}];
[_customTableView endUpdates];
customTableArray 是我的模型数组。 sortedArray 只是该数组的排序版本。当我点击加号按钮添加新行时运行此代码时,出现此错误:
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'无效更新:无效 第 0 节中的行数。包含在第 0 节中的行数 更新后的现有节(2)必须等于 更新 (1) 之前该部分中包含的行,加号或减号 从该部分插入或删除的行数(插入 2 行, 0 已删除)加或减移入或移出的行数 该部分(0 移入,0 移出)。'
我不确定我做错了什么。想法?谢谢。
【问题讨论】:
标签: iphone uitableview