我需要了解有關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。 預先感謝您。