Uitableview 如何在字典的根目录中显示数组名称

Uitableview 如何在字典的根目录中显示数组名称,uitableview,plist,root,Uitableview,Plist,Root,嗨,我有一个plist文件,我正在从它的层次结构中读取它,如下所示: 根词典 Date1数组(用字典填充) Date2数组(用字典填充) 等 如何用数组标题填充UITableView?您可以使用allKeys方法访问根NSDictionary的键: NSString *path = [[NSBundle mainBundle] pathForResource:@"MyData" ofType:@"plist"]; NSDictionary *rootDict = [[[NSDictionary

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

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


如何用数组标题填充UITableView?

您可以使用
allKeys
方法访问根
NSDictionary
的键:

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

}

答对 了反应很好。非常感谢。