0

私はxmlファイルを持っていて、xmlファイルのすべての情報を読み取り、配列に保存します。

配列に格納するための私の 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;

これを導入するのを手伝ってくれませんか

前もって感謝します

編集:

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] プレゼンテーション: (null) で、そのスライド数: 0 [788:c07] スライド ラベル: (null)

4

2 に答える 2

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];
于 2012-10-15T17:59:06.747 に答える
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]
}
于 2012-10-15T15:13:41.683 に答える