我需要了解有关NSManagedObjectContext更新的内容。 我有一个UITplitView与RootView上的UITableViewController和详细信息视图上的UIViewController。当我在一排数据挖掘,我加载一些数据标签和一个UITextView在那里我可以更新场:NSManagedObjectContext:是否autoupdate?
- (void)textViewDidEndEditing:(UITextView *)textView {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
[[listOfAdventures objectAtIndex:indexPath.row] setAdventureDescription:textView.text];
}
确定。这工作正常,描述更新。 另外,有些人可能想删除行:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"playerPlaysAdventure.adventureName==%@",[[listOfAdventures objectAtIndex:indexPath.row] adventureName]];
NSArray *results = [[AdventureFetcher sharedInstance] fetchManagedObjectsForEntity:@"Player" withPredicate:predicate withDescriptor:@"playerName"];
[moc deleteObject:[listOfAdventures objectAtIndex:indexPath.row]];
for (Player *player in results) {
[moc deleteObject:player];
}
[listOfAdventures removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
[self clearDetailViewContent];
NSError *error = nil;
if (![moc save:&error]) {
NSLog(@"Errore nella cancellazione del contesto!");
abort();
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
因此,这里是我的问题:如果我的评论我的MOC的储蓄行,冒险是只是暂时删除。如果您退出应用程序并重新打开该应用程序,该对象仍然存在。更新字段时不会发生这种情况。我想知道为什么,如果我还应该在textViewDidFinishEditing方法中保存moc。 预先感谢您。