UITableView Plist Not Returning valueForKey

I'm stuck in a rut over implementing a sectioned plist into a UITableView.

My plist setup is as followed. I have a root array with dictionaries representing sections. These dictionaries have a single string 'sectionname' that dictates the section header as well as an array of dictionaries inside to represent the cells (the reason for this was to allow the cells to be counted and still have a section header).

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

[And so forth].

Now, everything appears to be working, the correctly named headers are there and the correct number of rows are under their sections. However, the rows do not have labels and for the life of me I can't figure out why.

I have a NSMutableArray of the plist

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

The number of rows in section is thusly.

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

And the titles for headers.

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

I tried with the following to no avail.

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

I'm still learning and this was kind of botched together from different places. The 'doa' method links to another file where the 'libraryContent' is declared.

Do you guys have any idea how to get the names out of the plist? Or any other methods of doing what I'm trying to?


Try this code:

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

EDIT
This way the code will be more readable:

NSDistionary *sectionDataDict = [[doa libraryContent] objectAtIndex:indexPath.section];
NSArray *sectionRowsArray = [sectionDataDict objectForKey:@"RowsInSection"];
NSDictionary *rowDataDict = [sectionRowsArray objectAtIndex:indexPath.row];
cell.textLabel.text = [rowDataDict objectForKey:@"name"];
链接地址: http://www.djcxy.com/p/52418.html

上一篇: OpenGL着色器的显式和自动属性位置绑定

下一篇: UITableView Plist不返回valueForKey