2012-01-20 86 views
0

我有這個NSDictionary,我想加載到表視圖。它應該有一個單元格爲每個字典有一個單元格。所以在這種情況下有3個單元。加載NSDictionary到UITableView

friendsDictionary: (
     { 
     name = Down; 
     age = 15; 
     birthday = Today; 
    }, 
     { 
     name = Charlie; 
     age = 12; 
     birthday = Today; 
    }, 
     { 
     name = Chris; 
     age = 18; 
     birthday = Today; 
    } 

編輯:

NSString *path = [[NSBundle mainBundle] pathForResource:@"friendsList" ofType:@"plist"]; 
    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path]; 
    NSDictionary *myDictionary = [dict objectForKey:@"friends"]; 
    self.friendsDictionary = myDictionary; 
    [aDictionary release]; 
+3

祝你生日快樂,查理和克里斯! – JustSid

回答

2

你有什麼居然還有充滿了3個NSDictionaries一個NSArray。

在您的cellForRowAtIndexPath方法中,您可以使用self.friendsDictionary引用您的數組(假設您的數組是一個綜合屬性)。

因此,你可以做[[cell textLabel] setText:[[self.friendsDictionary objectAtIndex:indexPath.row] objectForKey:@"name"]];

檢查蘋果的TableViews示例代碼,瞭解如何設置您的UITableViewController子類的更多信息。記得執行numberOfRowsInSection:並返回[self.friendsDictionary count]