2010-09-23 73 views
0

我被困在实施一个UITableView分段plist的车辙。UITableView Plist不返回valueForKey

我的plist设置如下。我有一个包含代表段的字典的根数组。这些字典有一个单独的字符串'sectionname',它指定了部分头部以及内部代表单元格的字典数组(这是为了允许单元格被计数并且仍然具有部分头部)。

Root - Array 
    Item 0 - Dictionary 
     sectionname - string - A 
     RowsInSection - Array 
      Item 0 - Dictionary 
      name - string - Adam 
      Item 1 - Dictionary 
      name - string - Andrew 
    Item 1 - Dictionary 
     sectionname - string - B 
     RowsInSection - Array 
      Item 0 - Dictionary 
      name - string - Belle 
      Item 1 - Dictionary 
      name - string - Bob 
    Item 3 - Dictionary 

[等等]。

现在,一切似乎都在工作,正确命名的标题在那里,正确的行数在它们的部分之下。但是,这些行没有标签,对于我来说,我无法弄清楚为什么。

我有plist中

libraryContent = [[NSMutableArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:libraryPlist ofType:@"plist"]]; 

在部分行数是正是如此的NSMutableArray中。

NSInteger count = [[[[doa libraryContent] objectAtIndex:section] valueForKeyPath:@"[email protected]"]intValue]; 
return count; 

而标题的标题。

return [[[doa libraryContent] objectAtIndex:section] objectForKey:@"sectionname"]; 

我试着用下面的方法无济于事。

cell.textLabel.text = [[[doa libraryContent] objectAtIndex:indexPath.row] valueForKey:@"name"]; 

我还在学习,这是从不同的地方一起弄糟。 'doa'方法链接到声明'libraryContent'的另一个文件。

你们有没有想法如何从plist中得名?或者我想要做什么的其他方法?

回答

0

试试这个代码:

cell.textLabel.text = [[[[[doa libraryContent] objectAtIndex:indexPath.section] objectForKey:@"RowsInSection"] objectAtIndex:indexPath.row] objectForKey:@"name"]; 

编辑
这样的代码将更具可读性:

NSDistionary *sectionDataDict = [[doa libraryContent] objectAtIndex:indexPath.section]; 
NSArray *sectionRowsArray = [sectionDataDict objectForKey:@"RowsInSection"]; 
NSDictionary *rowDataDict = [sectionRowsArray objectAtIndex:indexPath.row]; 
cell.textLabel.text = [rowDataDict objectForKey:@"name"]; 
+0

感谢的是,它的工作完美。我曾尝试过一百万种不同的变体,而我正在接近解决这个问题。再一次感谢你的帮助。 – Ryan 2010-09-23 16:22:22

+0

很高兴我能帮助你。如果您接受答案,我将不胜感激。 – 2010-09-23 19:11:02