2012-04-17 31 views
0

我的XML解析器有一些问题,用obj-c编写。 解析器本身很好,但我不能访问DetailView中的结果数组。如何在另一个视图中访问NSArray

我需要由我的主和DetailViewController中的解析器类创建的数组值。

在MasterViewController我这样做:

MasterViewController.h

#import <UIKit/UIKit.h> 
#import "AppDelegate.h" 
#import "TouchXML.h" 
#import "Parser.h" 

@class Parser; 

@interface MasterViewController : UITableViewController{ 
    Parser *theParser; 
    } 

MasterViewController.m

- (void)viewDidLoad 
{ 
    theParser = [[Parser alloc] init]; 
    [theParser startParser:xmlPath]; //Now the parser runs and parses all needed values into arrays 
} 

然后我推点击的DetailView,我想有访问值太。

UniViewController.h

#import <UIKit/UIKit.h> 
#import "AppDelegate.h" 
#import "Parser.h" 

@interface UniViewController : UITableViewController{ 

    Parser *theParser; 
} 

UniViewController.m

- (void)viewDidLoad 
{ 
    NSLog(@"Name: %@",[[theParser.listArray objectAtIndex: 0]valueForKey:@"name"]); 
} 

在这里,我想从解析器访问数组,但我总是得到的值(NULL)? 在调试器中,我看到PERSER有0x0000,不能正确... 在执行了Parser = [[Parser alloc] init]之后;在这里,它有一个十六进制值,但我仍然得到(null)。

如何从DetailView访问数组值?

如果有人能在这里向我解释问题,那真的很不错。

谢谢。

回答

0

您的详细视图必须有一个指向您的马西德威(通过解析器)创建数组,试试这个:

(void)viewDidLoad 
{ 
    aParser = [[Parser alloc] init]; 
    [aParser startParser:xmlPath]; 
    myUniView.theParser = aParser; //myUniView is just the detail view you're pushing 

,然后在此之后,你可以把你的详细信息视图。

+0

作品完美,谢谢! – Nico 2012-04-18 00:54:45

+0

我怎样才能做到这一点与普通班,而不是视图?我试图访问我的数组在MapView的Annotation类。在MasterViewController中...在我推送DetailView之前,我这样做:Annotation * Anno = [[Annotation alloc] init]; Anno.theParser = theParser; 但我无法访问Annotation.m类中的数组? – Nico 2012-04-18 18:31:26

+0

是当您将其分配给注释时已经分配的解析器吗?你是否在整个应用程序中只使用一个分析器?如果是这样,你可以考虑让你的解析器类是一个单例,以便你可以从任何类中获得它 – 2012-04-18 18:36:42

相关问题