views:

216

answers:

2

Hello all ,

I seem to have a probably newbie problem but here it is. How do I get my dictionary from my parser class , which has building a tree for a drill down table back to my drilldowntabledelegate class. my app looks something like this.

@implementation DrillDownAppAppDelegate

@synthesize window;

@synthesize navigationController;

@synthesize data;

-(void)StartParser
{   
    //NSURL *url = [[NSURL alloc] initWithString:@"http://sites.google.com/site/virtuagymtestxml/testxml/Books.xml"];
    //NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    //local
    NSString *Path = [[NSBundle mainBundle] bundlePath];
    NSString *DataPath = [ Path stringByAppendingPathComponent:@"exercises.xml"];
    NSData *Data = [[NSData alloc] initWithContentsOfFile:DataPath];

    NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:Data];
    //Initialize the delegate.
    XMLParser *parser = [[XMLParser alloc] initXMLParser];

    //Set delegate
    [xmlParser setDelegate:parser];

    //Start parsing the XML file.
    BOOL success = [xmlParser parse];

    if(success){
     NSLog(@"No Errors");
    }
    else
    {
     NSLog(@"Error Error Error!!!"); 
    }

}


- (void)applicationDidFinishLaunching:(UIApplication *)application {

        [self startParser];

    NSString *Path = [[NSBundle mainBundle] bundlePath];
    NSString *DataPath = [Path stringByAppendingPathComponent:@"Tree2.plist"];

    NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];


         //this is what needs to happen
         **NSDictionary *tempDict = dictionaryFromMyParser**

    self.data = tempDict;
    [tempDict release];

    // Configure and show the window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];

}

My parser file looks something like this

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
  namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName 
    attributes:(NSDictionary *)attributeDict {

    if([elementName isEqualToString:@"exercises"]) {

      //init tree 
     Tree = [NSMutableDictionary new];
     Rows = [NSMutableArray new];
     [Tree setObject:Rows forKey:@"Rows"];

     //Initialize the array.
             ... all kinds of arrays here 
    }

if([elementName isEqualToString:@"menu_mob"]) {
     amenuMob = [[menuMob alloc]init];
    }

    if([elementName isEqualToString:@"menuitem"]) {
     amenuItem = [[menuItem alloc] init];
     amenuItem.IDE = [[attributeDict objectForKey:@"id"] integerValue];
     amenuItem.text = [attributeDict objectForKey:@"text"];

     NSLog(@"reading id menuitem %i", amenuItem.IDE);
     NSLog(@"reading text menuitem %@", amenuItem.text);
     [appDelegate.menuitems addObject:amenuItem];
}

I've been getting my inspiration and information from the following links

http://www.iphonesdkarticles.com/2009/03/drill-down-table-view-with-detail-view.html What works : 1) Building a nice tree which can be read into by my app ( tested it with writetoFile) 2) xmlparsing works ( i decent xmlfile ) 3) the drilldowntable example

conclusion: how do I get my (build by parser)Tree which has been build by my parser to my drilldowntableappdelegate ?

ps. if this doesn't work can I also build my parser in my delegate file ( i know sloppy but I assume my filled tree will work there )

A: 

change parser to return a reference to your tree?

ennuikiller
I'm sorry you got me confused a little ... what exactly do you mean ?
A: 

I sovled my problem. I solved my problem by creating the dictionary objects in my drilldownappdelegate file and then using them through the singleton UIApplication in my parser file.