【发布时间】:2013-12-13 17:56:43
【问题描述】:
我尝试创建一个聚合提要的应用程序。
我想在表格视图结束显示单元格时更改提要状态。
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
Feed* feed = [_fetchedResultsController objectAtIndexPath:indexPath];
if ([feed.read boolValue] == YES) return ;
feed.read = [NSNumber numberWithBool:YES];
[Feed save];
}
我使用 NSFetchedResultsController,当我更改提要状态时,我使用 reloadRowsAtIndexPath。
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath
{
switch(type) {
...
case NSFetchedResultsChangeUpdate:
[self.tableView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
break;
...
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
}
我滚动,didEndDisplayingCell 与良好的indexPath 一起调用,当tableView 结束更新时,它再次调用didEndDisplayingCell 与下一个indexPath。之后,我的核心数据出现了严重错误。
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. *** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2] with userInfo (null)
有什么想法吗?
【问题讨论】:
标签: ios iphone core-data nsfetchedresultscontroller