2010-09-23 70 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