2011-07-21 54 views
1

我有一個NSFetchRequest來搜索核心數據實體。它發現它們很好,但我想將單元格的文本設置爲實體的name屬性。如何從NSArray獲取名稱

我目前有這個,但我設置對象本身的標題,而不是名稱屬性,我該如何解決這個問題?

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Routine" inManagedObjectContext:self.managedObjectContext]; 
[fetchRequest setEntity:entity]; 
NSError *error = nil; 
NSArray *results = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; 
self.routineArray = results; 
[fetchRequest release]; 

cell.textLabel.text = [self.routineArray objectAtIndex:indexPath.row]; 

回答

3

嘗試:

cell.textLabel.text = [[self.routineArray objectAtIndex:indexPath.row] name]; 

編輯

如果您Routine實例是在routineArray(假設名字,我想):

// get the Routine instance 
Routine *r = [self.routineArray objectAtIndex:indexPath.row]; 
// now you got your instance, set anything you want on r... 
// ... 
// and then set its name as the text for textLabel using previous instruction 
+0

尼斯的作品。但有沒有辦法可以做到這一點,以便我可以實際檢索'Routine'對象?以便我可以根據需要修改它們。 – Jon

+0

如果你的'Routine'實例存儲在'routineArray'中,當然有。我將編輯。 – 2011-07-21 07:36:16

+0

另請考慮接受符合您需要的答案;) – 2011-07-21 07:43:19