将我的字典树从我的 xmlparser 类获取到我的rilldowntableappdelegate 文件

发布于 2024-07-26 22:51:00 字数 3025 浏览 4 评论 0原文

我似乎有一个可能是新手的问题,但就是这样。 如何从我的解析器类获取我的字典,该类已经为向下钻取表构建了一棵树,返回到我的钻取表委托类。 我的应用程序看起来像这样。

@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 有效(我体面的 xmlfile)
  3. drilldowntable 示例

结论:如何获取由我构建的(由解析器构建)树解析器到我的rilldowntableappdelegate?

附: 如果这不起作用,我也可以在我的委托文件中构建我的解析器(我知道很草率,但我认为我的填充树可以在那里工作)

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 all over the internet
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 )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹梦到西洲 2024-08-02 22:51:00

我解决了我的问题。
我通过在 drownappdelegate 文件中创建字典对象,然后通过解析器文件中的单例 UIApplication 使用它们来解决了我的问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文