2010-05-06 33 views
1

我試圖訪問我的數組中的單個元素。這是我嘗試訪問的數組內容的一個示例。從目標c中的數組訪問元素

<City: 0x4b77fd0> (entity: Spot; id: 0x4b7e580 <x-coredata://D902D50B-C945-42E2-8F71-EDB62222C0A7/Spot/p5> ; data: { 
    CityToProvince = 0x4b7dbd0 <x-coredata://D902D50B-C945-42E2-8F71-EDB62222C0A7/County/p15>; 
    Description = "Friend"; 
    Email = "[email protected]"; 
    Age = 21; 
    Name = "Adam"; 
    Phone = "+44175240"; 
}), 

我試圖訪問的姓名,電話等..

如何,我會去這樣做的元素呢?



UPDATE:
OK,那我在看現在的核心數據的理解,我會怎樣去除顯示在我的表視圖中的對象?

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSManagedObject *object = (NSManagedObject *)[entityArray objectAtIndex:indexPath.row]; 

    NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    } 



    // Configure the cell... 

    return cell; 
} 

回答

3

這看起來不像一個數組。這看起來像一個核心數據實體。你可能有一個他們,但它看起來好像你試圖訪問實體本身的成員。爲此,您可以使用NSManagedObject方法。

NSManagedObject *entity = /* ... retrieve entity from Core Data ... */; 
NSString *name = [entity valueForKey:@"Name"];