0

嗨,我有一个 plist 文件,我正在从它的层次结构中读取它,如下所示:

根 - 字典 Date1 数组(填充字典) Date2 数组(填充字典)等

如何用数组标题填充我的 UITableView?

4

1 回答 1

0

NSDictionary您可以使用以下方法访问根的密钥allKeys

NSString *path = [[NSBundle mainBundle] pathForResource:@"MyData" ofType:@"plist"];
NSDictionary *rootDict = [[[NSDictionary alloc] initWithContentsOfFile:path] autorelease];

NSLog(@"%@", [[rootDict allKeys] objectAtIndex:0]); // Should return Date1Array

因此,在您的 UITableViewDataSource 方法中,您可以访问正确的密钥:

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

// Assumes the plist's root dictionary has been retained using a property:
NSString *arrayName = [[self.rootDict allKeys] objectAtIndex:indexPath.row];

//... configure cell

}
于 2012-10-30T12:32:39.270 回答