2012-10-15 3 views
0

나는 XML 파일을 내가 XML 파일 및 배열의 ​​저장소에있는 모든 정보를 에드에서 배열을, 여기 다른 클래스의 목적-C

배열에 저장 내 starDidElement 파일입니다 방법 :

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI 
qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ 

if ([elementName isEqualToString:@"Presentation"]) { 
    NSLog(@"user element found – create a new instance of User class..."); 
    app.presentationArray = [[NSMutableArray alloc] init]; 
    thePresentation = [[Presentation alloc] init]; 
    thePresentation.pLabel = [attributeDict objectForKey:@"label"]; 
    NSLog(@"PLabel: %@", thePresentation.pLabel); 

}else if ([elementName isEqualToString:@"slides"]) { 
    NSLog(@"Slides"); 

    thePresentation.slides = [NSMutableArray array]; 

내 헤더에 나는

Presentation thePresentation; 

당신이

감사를 inpelement 저를 도와주세요을드립니다 전진

편집 :

Presentation *aPresentation = [app.presentationArray objectAtIndex:0]; 
NSLog(@"Presentation is: %@ and it's Slide Count is: %d",aPresentation.pLabel, aPresentation.slides.count); 

Slide *aSlide = [aPresentation.slides objectAtIndex:0]; 
NSLog(@"Slide Label is: %@", aSlide.sLabel); 

UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
[btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal]; 
btn.frame = rect; 
[btn setTag:i]; 
[btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; 
[imageView addSubview:btn]; 

그 다음 로그

이다 [788 : C07] 프리젠 테이션은, (널)과 슬라이드 카운트가요 : 0 [788 : C07] 슬라이드 레이블입니다 : (null)

+0

을 당신은 본질적으로 같은 방법으로 그것을 당신은 자바에서 할 것 . –

+0

@HotLicks는 응답 부분에 코드를 쓸 수 있습니까? – AntonMac

답변

0

당신의 viewController에 public 메서드를 추가합니다. xml 구문 분석이 완료되면 public 메서드를 호출하면 viewController 데이터가 준비되었습니다. & UI를 업데이트하십시오.

appDelegate를 사용하여 viewController의 인스턴스를 가질 수 있으므로 appDelegate를 사용하여 viewController에 데이터 준비가되었음을 알릴 수 있습니다.

편집 : 당신이 할 수있는 사항은 다음과 같습니다

//in viewController.h 
- (void) viewFillUp; 

//in viewController.m 
-(void)viewFillUp 
{ 
     Slide *aSlide = [thePresentation.slides objectAtIndex:0]; 
     NSLog(@"Slide Label is: %@", aSlide.sLabel); 

     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal]; 
     btn.frame = rect; 
     [btn setTag:i]; 
     [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; 
     [imageView addSubview:btn]; 
} 

//in appDelegate.h 
- (void) parsingDone; 

//in appDelegate.m 
- (void) parsingDone 
{ 
    //suppose ur viewController instance is self.viewController 
    [self.viewController viewFillUp] 
} 
+0

하지만 나는 프레젠테이션 thePresentation을 가지고 있습니다. , 당신은 당신이 의미하는 코드를 작성 하시겠습니까 – AntonMac

+0

어디에 ur startDidElement 코드 작성 ..? 내 클래스 또는 viewController – vishy

+0

내 XMLParser에 – AntonMac

2

당신이 그것을 이런 식으로 할 때 어떤 일이 :

Presentation *aPresentation = [app.presentationArray objectAtIndex:0]; 
NSLog(@"Presentation is: %@ and it's Slide Count is: %d",aPresentation.pLabel, aPresentation.slides.count); 

Slide *aSlide = [aPresentation.slides objectAtIndex:0]; 
    NSLog(@"Slide Label is: %@", aSlide.sLabel); 

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [btn setTitle:[NSString stringWithString:aSlide.sLabel] forState:UIControlStateNormal]; 
    btn.frame = rect; 
    [btn setTag:i]; 
    [btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside]; 
    [imageView addSubview:btn]; 
+0

먼저 AppDelegate * app을 추가 한 선언되지 않은 식별자 app에 오류가있었습니다. 내 헤더 파일에 있지만 잡히지 않은 예외 'NSInvalidArgumentException'으로 인해 응용 프로그램을 종료하는 중 오류가 발생했습니다. 이유 : '*** - [NSPlaceholderString initWithString :] : nil arguments' – AntonMac

+0

[788 : c07] 프레젠테이션은 (null)이며 슬라이드입니다. 개수 : 0 [788 : c07] 슬라이드 라벨 : (null) – AntonMac

+0

즉, 'app.presentationArray'에 아무 것도 없음을 의미합니다. 프레젠테이션이 추가되지 않았습니다. –