J'ai besoin de comprendre quelque chose à propos de la mise à jour NSManagedObjectContext. J'ai un UISplitView avec un UITableViewController sur le RootView et un UIViewController dans la vue détaillée. Lorsque je tape dans une rangée avec des données, charger des données dans des étiquettes et un UITextView où je peux mettre à jour ce champ:NSManagedObjectContext: autoupdate ou non?
- (void)textViewDidEndEditing:(UITextView *)textView {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
[[listOfAdventures objectAtIndex:indexPath.row] setAdventureDescription:textView.text];
}
Ok. Cela fonctionne correctement, la description est mise à jour. En outre, quelqu'un pourrait veut supprimer une ligne:
- (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
}
}
Alors, voici mon problème: si je commente les lignes sur l'enregistrement de mon MOC, l'aventure n'est supprimé momentanément. Si vous quittez l'application et la rouvrez, l'objet est toujours là. Cela n'arrive pas avec la mise à jour d'un champ. Je voudrais savoir pourquoi et si je devrais enregistrer moc aussi dans la méthode textViewDidFinishEditing. Merci d'avance.