2012-04-17 2 views
0

obj-c로 작성된 XML 파서에 문제가 있습니다. 파서 자체는 괜찮지 만 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"]); 
} 

? 디버거에서 theParser에 0x0000이 있다는 것을 알았습니다 ... theParser = [[Parser alloc] init]; 여기에 16 진수 값이 있지만 여전히 (null) 값을 얻습니다.

어떻게 DetailView에서 Array 값에 액세스 할 수 있습니까?

누군가 내게이 문제를 설명 할 수 있다면 정말 좋을 것입니다.

감사합니다.

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

를하고이 후 당신은 당신의 상세보기를 밀어 수 있습니다

답변

0

귀하의 상세보기가 MasterView이 (파서를 통해) 생성 배열에 대한 포인터를 가지고있다,이 시도.

+0

완벽하게 작동합니다. 감사합니다. – Nico

+0

보기가 아닌 일반 클래스를 사용하면 어떻게됩니까? MapView의 Annotation Class에서 내 Array에 액세스하려고합니다. MasterViewController에서 DetailView를 누르기 전에 다음과 같이합니다 : Annotation * Anno = [[Annotation alloc] init]; Anno.theParser = theParser; 하지만 Annotation.m 클래스의 Array에 액세스 할 수 없습니까? – Nico

+0

은 주석을 주석에 할당 할 때 이미 할당 된 파서입니까? 또한 응용 프로그램 전체에서 파서 하나만 사용하고 있습니까? 그렇다면 파서 클래스를 싱글 톤으로 만들어 모든 클래스에서 접근 할 수 있도록 할 수 있습니다. –

관련 문제