3

pickerView が文字列をデータ値として使用できるように、一連の Core Data オブジェクト (NSStrings) を NSMutableArray に追加しようとしています。

現在、textField の文字列を一度に 1 つずつコア データの 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];

}

どんな助けでも大歓迎です。クリス

4

1 に答える 1

3

NSFetchRequest を使用して、データを配列にフェッチできます。コア データ プログラミング ガイド - Fetching Managed Objectを参照してください。リンクの最初のセクションを読むだけです。

フェッチリクエストを実行すると、配列が返されます

NSArray *array = [moc executeFetchRequest:request error:&error];
于 2010-02-13T23:55:22.243 に答える