【发布时间】:2013-10-04 00:22:25
【问题描述】:
我有一个 plist,它是一个包含字典的数组。我正在尝试在表格视图中打印出名称,但是名称没有显示出来。到目前为止我所拥有的是以下代码
self = [super init];
if (self) {
// Fetch from the app bundle... load the NSDictionary
_qList = [NSArray arrayWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"plist"]];
_qNames=[_qList valueForKey:@"Name"];
}
return self;
对于我的表格视图,我有
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
int index = [indexPath indexAtPosition:1];
NSString *key = [[self.test.qNames valueForKey:@"Name"] objectAtIndex:index];
NSString *value = [self.test.qNames objectForKey:key];
[[cell textLabel] setText:value];
return cell;
}
我的plist结构如下:
根(数组) -第 0 项(字典) -姓名 -班级 -年龄 -第 1 项(字典) -姓名 -班级 -年龄
等等..
我只需要弄清楚如何放置
NSDictionary *name=[self.model.qList valueForKey:@"Name"];
我返回表格视图的名称?
【问题讨论】:
-
_qNames=[_qList valueForKey:@"Name"];正在返回名称
-
如果 qList 是一个数组,为什么要使用 valueForKey?您不想使用 objectAtIndex: 来获取字典之一,然后开始挑选单个值吗?
-
_qNames=[_qList valueForKey:@"Name"];正在返回我在 plist 中的 20 个名称。 qlist 是一个数组,但在那个数组里面我有一个字典