我有一个应用程序使用连接到UITableView
的NSFetchedResultsController
。NSFetchedResultsController覆盖插入的最后一个单元格
我遇到了一个非常奇怪的问题,因为当一个新的项目应该出现在表格底部的插入完成后,最后一个项目的单元格会被新插入的项目替换 - 屏幕现在显示我刚刚插入的项目,但在此之前的项目已丢失。进一步插入显示相同的行为,表不增长,最后一项被替换为任何新项目。
重新启动应用程序时,应该显示完整的数据表(换句话说,覆盖的单元格在数据库中仍有数据)。看起来结果控制器失去了新项目应该去的地方。
的之前和之后的一个例子:
ADDITION:
现有代码controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
UITableView *fetchTableView = [self tableViewForFetchedResultsController:controller];
switch(type) {
case NSFetchedResultsChangeInsert:
[fetchTableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
///....
}
这取决于您如何更新表,大概在fetchd结果控制器委托回调中。请显示你的代码。 – Mundi 2013-02-09 11:04:11