我有 3 个场景,每个场景都收集用户的输入。每个场景有 5 个 UITextField。第 4 个场景显示了 UITableView 中的所有 15 个文本字段。
我不确定这是否是最好的方法,但我有以下场景 1 的代码:
//Meetings is NSManagedObject class. Meetings.h and .m was created from the Meetings entity from Core Data
//I have this code once in the file right before I start saving the data
Meetings *meetings = (Meetings *) [NSEntityDescription insertNewObjectForEntityForName:@"Meetings" inManagedObjectContext:self.managedObjectContext];
// I have similar code below for each user's input.
NSString *date = [[NSString alloc] initWithFormat:@"%@", [dateFormatter stringFromDate:selectedDate]];
DateLabel.text = date;
[meetings setDateLabel:date];
...
[meetings setTimeLabel:time];
..
//Code below is to save. I have this once at the end of the file to save the data
NSError *error = nil;
if (![managedObjectContext save:&error]) {
// Handle the error.
}
//The log below shows the saved data fine. Thus, the data is being saved in managnedObjectContext.
NSLog (@"This is the DateLabel %@", meetings.DateLabel);
问题:如何访问场景 2 和 3 中的指针 *meetings 以保存 managedObjectContext 中的其余字段?我从场景 2 中做了一个 NSLog,它显示为 Null:
//In Scene 2 viewDidLoad method I did the following to check:
self.managedObjectContext = [(STAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
Meetings *meetings = (Meetings *) [NSEntityDescription insertNewObjectForEntityForName:@"Meetings" inManagedObjectContext:self.managedObjectContext];
NSLog (@"This is the DateLabel from Scene 2 %@", meetings.DateLabel);
日志显示:
2013-02-11 18:04:05.447 MyApp[3505:c07] This is the DateLabel from Scene 2 (null)