obtenir mon arbre dictionnaire de ma classe xmlparser .. à mon dossier drilldowntableappdelegate

StackOverflow https://stackoverflow.com/questions/1150076

Question

Il me semble avoir un problème probablement débutant, mais ici il est. Comment puis-je obtenir mon dictionnaire de ma classe d'analyseur, qui a la construction d'un arbre pour une table drill down retour à ma classe drilldowntabledelegate. mon application ressemble à quelque chose comme ça.

@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 me suis fais l'inspiration et l'information de tous sur Internet Ce qui fonctionne:

  1. Construire un bel arbre qui peut être lu dans mon application (testé avec WriteToFile)
  2. fonctionne xmlparsing (I xmlfile décent)
  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, je peux aussi construire mon analyseur dans mon dossier délégué (je sais bâclée, mais je suppose que mon arbre rempli va y travailler)

Était-ce utile?

La solution

Je sovled mon problème. Je résolu mon problème en créant les objets du dictionnaire dans mon fichier drilldownappdelegate puis les utiliser à travers le UIApplication singleton dans mon fichier analyseur.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top