【发布时间】:2013-04-05 08:17:21
【问题描述】:
视图控制器的数据模型会不断且积极地更新
经常调用 UItableview (storyTable) 来更新和反映迄今为止的更改。
(更改代码以仅反映单个 beginUpdates endUpdates) - 仍然崩溃
[self.storyTable beginUpdates];
if([deleteIndexPaths count]){
DLog(@"Table refresh delele rows :%@",deleteIndexPaths);
[self.storyTable deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation:UITableViewRowAnimationNone];
}
if ([addIndexPaths count]){
DLog(@"Table refresh add rows :%@",addIndexPaths);
[self.storyTable insertRowsAtIndexPaths:addIndexPaths withRowAnimation:UITableViewRowAnimationTop];
}
if ([changedIndexPaths count]){
DLog(@"Table refresh change rows :%@",changedIndexPaths);
[self.storyTable reloadRowsAtIndexPaths:changedIndexPaths withRowAnimation:UITableViewRowAnimationFade ];
}
[self.storyTable endUpdates];
//[self.storyTable endUpdates];
tableIsAnimating = NO;
}
不时崩溃并显示以下消息: (主要在 deleteRowsAtIndexPaths...)
* -[UITableView _endCellAnimationsWithContext:] 中的断言失败,/SourceCache/UIKit/UIKit-2380.17/UITableView.m:1070
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'无效更新:无效 第 0 节中的行数。包含在第 0 节中的行数 更新后的现有节(20)必须等于 更新前该部分中包含的行 (20),加号或减号 从该部分插入或删除的行数(0 插入, 10 已删除)加上或减去移入或移出的行数 该部分(0 移入,0 移出)。'
或:
* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“尝试插入第 20 行 进入第 0 节,但在第 0 节之后只有 20 行 更新”
问题:如何添加一些保护代码来防止崩溃?
【问题讨论】:
-
您有什么理由不想使用
NSFetchedResultsController和NSFetchedResultsControllerDelegate来显示模型更改?你没有使用 Core Data 吗?
标签: iphone ios objective-c ipad uitableview