Ich verwende CoreData mit iPhone SDK. Ich mache eine Notizen App. Ich habe eine Tabelle mit Notizobjekten, die von meinem Modell angezeigt werden. Wenn eine Schaltfläche gedrückt wird, möchte ich den Text in der Textansicht in dem Objekt speichern, das bearbeitet wird. Wie mache ich das? Ich habe mehrere Dinge versucht, aber keiner scheint zu funktionieren.Objekt in CoreData speichern
Dank
EDIT:
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setValue:detailViewController.textView.text forKey:@"noteText"];
NSError *error;
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();
}
Der obige Code es richtig spart, sondern es speichert es als neues Objekt. Ich möchte, dass es so gespeichert wird, wie ich es in meiner TableView ausgewählt habe.
Danke, eigentlich hat das gerade funktioniert. Musste es ein bisschen ändern, weil ich mit dem iPad arbeite, aber im Grunde den gleichen Code. Vielen Dank – John