2010-02-13 6 views
3

NSMutableArray에 코어 데이터 객체 (NSStrings)를 추가하여 pickerView가 해당 데이터 값으로 문자열을 사용할 수있게하려고합니다.iPhone 코어 데이터 객체가 NSMutableArray에 추가되었습니다.

현재 코어 데이터의 sqlite 파일에 한 번에 하나씩 textField에서 문자열을 저장할 수 있습니다.

코어 데이터 sqlite 파일에서 해당 객체를 NSMutable 배열로 다시 가져 오는 데 문제가 있습니다.

- (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]; 

} 

어떤 도움을 크게 감상 할 수 ...

-(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]; 

[email protected]""; 
self.viewDidLoad; 

[textField resignFirstResponder]; 
} 

가 지금 내가 가진 ... sqlite가 파일에 개체를 추가하는 코드입니다. Chris

답변

3

NSFetchRequest를 사용하여 데이터를 배열로 가져올 수 있습니다. Core Data Programming guide - Fetching Managed Object을 살펴보십시오. 링크의 첫 번째 섹션 만 읽으면됩니다. 응답에 대한 배열을

NSArray *array = [moc executeFetchRequest:request error:&error]; 
+0

확실히 반환 페치 요구를 실행

. 배열에 객체를로드 할 수 있었지만 정확한 질문을하지 않았습니다. 배열에 객체 속성 "eventName"을로드하려고합니다. 그래서 문자열의 배열을 NSManagedObjects 배열이 것입니다. – OscarTheGrouch

+0

일단 NSManagedObjects 배열이 있으면 각 항목에 루프를 수행하여 eventName 만 다른 배열에 넣을 수 있습니다. –

관련 문제