我似乎有一个可能的新手的问题,但这里它是。我怎么得到我的字典自我分析器类,其中有建树的一个深表回到我的drilldowntabledelegate类。我的程序看起来像这样的东西。

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

}

我的分析程序文件看起来像这样的东西

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

我已经得到我的灵感和信息,从所有在互联网上 什么工作:

  1. 建设一个漂亮的树可以读到我的程序(测试,它与writetoFile)
  2. xmlparsing工作(I体面的文件)
  3. 该drilldowntable例

结论:我怎么得到我的(建立由parser)树已经建立由我的分析器来我drilldowntableappdelegate?

ps。如果这不起作用我也可以建立我析器在我的委托的文件(我知道邋遢的但是我猜我的充满树将在那里工作)

有帮助吗?

解决方案

我sovled我的问题。我解决我的问题通过创建的字典对象在我drilldownappdelegate文件,然后使用他们通过单独通过在我的分析器的文件。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top