我正在使用HTTP GET方法从Web中提取数据 . 然后我从Web获取JSON数据并将其保存到CoreData中 . 我有一个带有自定义UITableViewCells的UITableView,它使用NSFetchedResultsController进行更新 .
但是当我去保存数据时,tableView只会更新屏幕上的内容,当我向下滚动时,tableView变为白色 .
在日志中,我收到了一些错误:
CoreData:错误:严重的应用程序错误 . 在调用-controllerDidChangeContent:期间,从NSFetchedResultsController的委托中捕获到异常 . 尝试使用userInfo(null)删除并重新加载相同的索引路径({length = 2,path = 0 - 43})
这是我的代码,NSFetchedResultsControllerDelegate在didChangeObject方法中使用:
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]
withRowAnimation:UITableViewRowAnimationFade];
break;
}
我能做什么的想法?
谢谢!
1 回答
那你呢:?
你可以拿我的,它应该肯定有用,我在几个项目中使用它 . 只需使tableViewController成为子类的子类 . 然后初始化并将fetchedResultsController传递给tableViewController并在其中调用:
SMCoreDataTableViewController.m:
SMCoreDataTableViewController.h: