【发布时间】:2010-03-27 20:19:36
【问题描述】:
我在 iPhone SDK 中使用 CoreData。我正在制作一个笔记应用程序。我有一个表格,其中包含从我的模型中显示的注释对象。当按下按钮时,我想将 textview 中的文本保存到正在编辑的对象中。我该怎么做呢?我一直在尝试几件事,但似乎都没有。
谢谢
编辑:
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();
}
上面的代码正确保存了它,但它保存为一个新对象。我希望它保存为我在 tableView 中选择的那个。
【问题讨论】: