我正在尝试将一堆核心数据对象(NSStrings)添加到 NSMutableArray 中,以便我的 pickerView 可以将字符串用作其数据值。
目前,我可以一次将一个文本字段中的字符串保存到 Core Data 中的 sqlite 文件中。
我无法将这些对象从 Core Data sqlite 文件中拉回 NSMutable 数组中。
这是将对象添加到 sqlite 文件的代码...
-(IBAction)addToPicker
{
CoreDataPickerAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSManagedObject *thePerson = [NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:context];
[thePerson setValue:textField.text forKey:@"eventName"];
[context save:&error];
textField.text=@"";
self.viewDidLoad;
[textField resignFirstResponder];
}
现在我有...
- (void)viewDidLoad {
NSMutableArray *array = [[NSMutableArray alloc] init];
//code needed to send all the objects in the sqlite Core Data store into array to be read by the pickerView
self.pickerData = array; // the picker uses NSMutableArray pickerData for its data
[array release];
[super viewDidLoad];
}
任何帮助将不胜感激。克里斯