Objective c 如何在另一个视图中访问NSArray

Objective c 如何在另一个视图中访问NSArray,objective-c,ios,nsmutablearray,nsarray,Objective C,Ios,Nsmutablearray,Nsarray,我的XML解析器(用obj-c编写)有一些问题。 解析器本身很好,但我无法访问DetailView中的结果数组 我需要在Master和DetailViewController中由解析器类创建的数组的值 在MasterViewController中,我执行以下操作: MasterViewController.h #import <UIKit/UIKit.h> #import "AppDelegate.h" #import "TouchXML.h" #import "Parser.h"

我的XML解析器(用obj-c编写)有一些问题。 解析器本身很好,但我无法访问DetailView中的结果数组

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

在MasterViewController中,我执行以下操作:

MasterViewController.h

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

@class Parser;

@interface MasterViewController : UITableViewController{
    Parser *theParser;
    }
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Parser.h"

@interface UniViewController : UITableViewController{

    Parser *theParser;
}
然后我点击DetailView,我也想访问那里的值

UniViewController.h

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

@class Parser;

@interface MasterViewController : UITableViewController{
    Parser *theParser;
    }
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "Parser.h"

@interface UniViewController : UITableViewController{

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

如何从DetailView访问数组值

如果有人能在这里给我解释一下这个问题,那就太好了


谢谢。

您的详细视图必须有一个指向MasterView创建的数组的指针(通过解析器),请尝试以下操作:

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

然后,您可以推送详细视图。

如何使用普通类而不是视图来进行此操作?我正在尝试访问MapView注释类中的数组。在MasterViewController中。。。在推送DetailView之前,我会这样做:Annotation*Anno=[[Annotation alloc]init];Anno.theParser=theParser;但是我无法访问Annotation.m类中的数组?当您将解析器分配给注释时,是否已经分配了它?您是否在整个应用程序中只使用一个解析器?如果是这样,你可以考虑让你的解析器类成为一个单体,这样你就可以从任何CLASIS注释*[ANNO] [[注释OLC] init ]中得到它;正当我在Anno.theParser=theParser;之前这样做;。。。我将看一看单音,看一看它们,不,我的意思是:您是否在代码中的某个地方执行Parser=[[Parser alloc]init];在将其分配给您之前,我先执行Parser=[[Parser alloc]init];在viewDidLoad主视图控制器中。只是找不到问题。。。我做的事情和以前一样。。。