您需要NSFetchedResultsController在主视图中使用 a 。将选定的核心数据对象传递给要编辑的详细视图。当保存发生时,您可以利用NSFetchedResultsControllerDelegate协议实现对表视图的自动回调。
在协议回调中,事情非常简单。这是didChangeObject回调的完整存根。
-(void)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath {
if (type == NSFetchedResultsChangeDelete) {}
else if (type == NSFetchedResultsChangeInsert) {}
else if (type == NSFetchedResultsChangeMove) {}
else if (type == NSFetchedResultsChangeUpdate) {
[self.tableView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell setSelected:YES animated:YES];
}
}
通常不需要选择内容(最后两行),但有时选择会丢失 - 如果您想保留选择的视觉指示,请使用此选项。