Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

tiltem

macrumors newbie
Original poster
Oct 18, 2010
25
0
I have a plist with the following structure:

<dictionary>
- <array>
--- <dictionary>
--- <dictionary>
--- <dictionary>
--- <dictionary>
--- <dictionary>
- <array>
--- <dictionary>
--- <dictionary>
--- <dictionary>
--- <dictionary>


I need to know how to add the contents of a key within the nested dictionaries into a tableViewCell from within the:

Code:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


method.
That is each nested dictionary has a key named "type" i need the populate the table with the values for the objectForKey:mad:"type" within all arrays.

I know how to do it for just one array, but not sure how to go to the next one. hope this makes sence, and thanks for the help!
 
Last edited by a moderator:
Try doing this:

Code:
NSEnumerator *enumerator = [baseDictionary keyEnumerator];
id key;
		
while ((key = [enumerator nextObject])) {
    NSArray *array = [baseDictionary objectForKey:key];

    NSEnumerator *arrayEnumerator = [array objectEnumerator];
    id someDictionary;
					
    while(someDictionary = [arrayEnumerator nextObject])
    {
        // we have the needed dictionary
        NSString *type = [someDictionary objectForKey:@"type"];
    }
}
 
I ended up changing my plist a little. Added an array to the root:
<array>
-<dictionary>
-- <array>
--- <dictionary>
--- <dictionary>
--- <dictionary>
--- <dictionary>
--- <dictionary>
-<dictionary>
-- <array>
--- <dictionary>
--- <dictionary>
--- <dictionary>
--- <dictionary>

then creating a new array to hold only the arrays with a

Code:
for (NSDictionary *dict in myPlist){
   if([dict objectForKey:@"theArray"]){
       [newArray addObjectsFromArray:[dict objectForKey:@"theArray"]];
  }
}

They are all in one section of the table. If there is a more direct way of doing it please share :)

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.