Yes. Here's how we did it:
In our XML syntax, we have this method that loads xml into a dictionary called dict:
-(NSDictionary *)getNodeDictionary:(Node *)node { if (node->level == 0) return xmlData; else { NSDictionary *dict = xmlData; for(int i=0;i<node->level;i++) { if ([[dict allKeys] containsObject:SUBNODE_KEY]) dict = [[dict objectForKey:SUBNODE_KEY] objectAtIndex:*(node->branches+i)]; } return dict; } }
And this method
-(NSDictionary *)getDataForNode:(Node *)node { NSDictionary* dict = [[self getNodeDictionary:node] copy]; return dict;
}
In the RadioData class, we have an instance variable:
Node *rootNode;
and a set of methods
-(Node *)getSubNodesForNode:(Node *)node; -(Node *)getSubNodeForNode:(Node *)node atBranch:(NSInteger)branch; -(Node *)getParentNodeForNode:(Node *)node; -(NSInteger)getSubNodeCountForNode:(Node *)node; -(NSDictionary *)getDataForNode:(Node *)node;
and property
@property (nonatomic) Node *rootNode;
Finally, in ViewController, when we run the frame, we use:
radioData = data; curNode = data.rootNode;
and inside cellForRowAtIndexPath we have:
Node* sub = [radioData getSubNodeForNode:curNode atBranch:indexPath.row]; NSDictionary* dets = [radioData getDataForNode:sub];
and in the didSelectRowAtIndexPath file:
Node* node = [radioData getSubNodeForNode:curNode atBranch:indexPath.row]; NSDictionary* data = [radioData getDataForNode:node];
This is probably more than you wanted, but this is a general outline.
Michael morrison
source share