我对使用 CoreData 进行编程有点陌生,所以我不知道如何去做。我正在尝试更新存储在 CoreData 对象中的字符串,但我对如何执行此操作一无所知。这是我的代码:
这是我制作新对象的地方:
- (void)insertNewObject:(id)sender
{
self.steakName = @"No Name";
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
[newManagedObject setValue:self.steakName forKey:@"steakName"];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
这是我要更新它的地方:(它正在与制作它的地方不同的类中更新。)
- (IBAction)update:(id)sender {
MasterViewController *masterViewController = [[MasterViewController alloc] init];
masterViewController.steakName = [self.steakNameTextField text];
self.detailDescriptionLabel.text = masterViewController.steakName;
NSLog(masterViewController.steakName);
}
谢谢您的帮助!:)