2009-07-19 5 views
0

Je semble avoir un problème probablement newbie mais ici il est. Comment puis-je obtenir mon dictionnaire à partir de ma classe d'analyseur, qui a construit un arbre pour une table d'exploration vers ma classe drilldowntabledelegate. mon application ressemble à quelque chose comme ça.obtenir mon arbre dictionnaire de ma classe xmlparser .. à mon fichier drilldowntableappdelegate

@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]; 

} 

Mon fichier analyseur ressemble à ceci

- (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]; 
} 

je reçois mon inspiration et d'information de tous sur Internet Ce qui fonctionne:

  1. Construire un bel arbre qui peut être lu par mon application (testé avec writetoFile)
  2. xmlparsing works (je décent xmlfile)
  3. l'exemple drilldowntable

conclusion: comment puis-je obtenir mon (construire par l'analyseur) Arbre qui a été construit par mon analyseur à mon drilldowntableappdelegate?

ps. si cela ne fonctionne pas, puis-je également construire mon analyseur dans mon fichier de délégué (je sais bâclé mais je suppose que mon arbre rempli fonctionnera là)

Répondre

0

J'ai résolu mon problème. J'ai résolu mon problème en créant les objets du dictionnaire dans mon fichier drilldownappdelegate, puis en les utilisant via l'UIApplication singleton dans mon fichier analyseur.

Questions connexes