NSManagedObjectContext 업데이트에 대해 이해해야합니다. RootView에는 UITableViewController가 있고 Detail View에는 UIViewController가있는 UISplitView가 있습니다.NSManagedObjectContext : 자동 업데이트 또는 안 함?
- (void)textViewDidEndEditing:(UITextView *)textView {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
[[listOfAdventures objectAtIndex:indexPath.row] setAdventureDescription:textView.text];
}
확인 : 나는 데이터 행에 탭 때, 나는 라벨로 일부 데이터와 나는 그 필드를 업데이트 할 수있는 UITextView를로드합니다. 이것은 올바르게 작동하며 설명이 업데이트됩니다. 또한 는, 누군가가 수도 행을 삭제하려고 :
- (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의 구원에 대한 행을 언급하면, 모험은 일시적으로 삭제됩니다. 앱을 종료하고 다시 열면 개체가 아직 남아 있습니다. 이것은 필드 업데이트로는 발생하지 않습니다. 내가 왜 moc를 textViewDidFinishEditing 메서드에서도 저장해야하는지 알고 싶습니다. 미리 감사드립니다.