Je possède ce code:Comment mettre à jour NSManagedObject?
-(void)didEditCard:(NSMutableArray*)theArray {
// Create a new instance of the entity managed by the fetched results controller.
NSManagedObject *newManagedObject = [[self fetchedResultsController] objectAtIndexPath:theSIndePath];
// If appropriate, configure the new managed object.
[newManagedObject setValue:[theArray objectAtIndex:0] forKey:@"frontCard"];
[newManagedObject setValue:[theArray objectAtIndex:1] forKey:@"flipCard"];
}
je savais qui a réussi objet a été touché à la vue du tableau. Si le joueur touche une cellule, une vue apparaît et il peut modifier les entrées. S'il clique sur done alors la méthode ci-dessus sera appelée. BTW rien n'est nul. Mais si j'appelle setValue, je ne serai pas mis à jour dans les données de base.
Mon objectif est: Je souhaite mettre à jour un objet géré qui doit mettre à jour le fichier de données de base ou supprimer l'objet du fichier de données de base et ajouter le nouveau au même endroit.
Quelqu'un peut-il m'aider s'il vous plaît?
modifier:
j'ai essayé ceci: mais il ne fonctionne pas: (il n'a pas est mis à jour)
-(void)didEditCard:(NSMutableArray*)theArray {
// Create a new instance of the entity managed by the fetched results controller.
NSManagedObject *managedObject = [[self fetchedResultsController] objectAtIndexPath:theSIndePath];
// If appropriate, configure the new managed object.
[managedObject setValue:[theArray objectAtIndex:0] forKey:@"frontCard"];
NSManagedObjectContext *context = [[self fetchedResultsController] managedObjectContext];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
personne, [. Quel est le problème? – cocos2dbeginner
Est-ce que theSIndePath est un objet global? Vous ne le transmettez pas dans cette méthode. – Walter
@walter oui c'est une variable globale et ce n'est pas nul – cocos2dbeginner