0

私は別のページにUILabelあり、ファイルUIButtonからタイトルを読みたいのですが、値を取得しました。使用したときのクラスでは答えはありますが、設定したいときは、この実装で私を助けてくれませんか?xmlNULLXML parserNSLOGNULL

前もって感謝します!

私のXMLパーサー:

- (Presentation1NameXML *) initXMLParser {

appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];

return self;
}

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


if ([elementName isEqualToString:@"Presentation1Name"]) {
    appDelegate.books = [[NSMutableArray alloc] init];
    NSLog(@"The Prices Count");
}
else if ([elementName isEqualToString:@"Presentation"]) {
    presentation = [[Presentation alloc] init];
    presentation.pLabel = [attributeDict objectForKey:@"label"];
    NSLog(@"khengggg %@",presentation.pLabel);
//    }else if ([elementName isEqualToString:@"Slides"]){
//        slides = [[Slide alloc] init];
}

if([elementName isEqualToString:@"slide"]) {

            slid = [[Slide alloc] init];
            NSLog(@"Processing Element: %@", elementName);

            slid.index = [[attributeDict objectForKey:@"index"] integerValue];
           NSLog(@"Reading index value :%i", slid.index);


            slid.sLabel = [attributeDict objectForKey:@"label"];
            NSLog(@"Reading label value :%@", slid.sLabel);

            slid.identifier = [attributeDict objectForKey:@"identifier"];
        NSLog(@"Reading identifier value :%@", slid.identifier);

       }
      NSLog(@"Processing Element: %@", elementName);
    }


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

if(!currentElementValue)
    currentElementValue = [[NSMutableString alloc] initWithString:string];
else
    [currentElementValue appendString:string];

NSLog(@"Processing Value: %@", currentElementValue);

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
 namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if([elementName isEqualToString:@"Presentation1Name"]){
    return;

}

if([elementName isEqualToString:@"Presentation"]) {
    [appDelegate.books addObject:presentation];
    presentation = nil;

}

//    if ([elementName isEqualToString:@"Slides"]){
//        [appDelegate.books addObject:slides];
//        slides = nil;
//        return;
//    }

if ([elementName isEqualToString:@"slide"]){
    [appDelegate.books addObject:slid];
    slid = nil;

}else
    [presentation setValue:currentElementValue forKey:@"pLabel"];
    //[presentation setValue:currentElementValue forKey:elementName];
currentElementValue = nil;
}

私のレーベルコード:私は(null)を得ました

appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];
label.textColor = [UIColor greenColor];
Presentation *p1 = [appDelegate.books objectAtIndex:0];
NSLog(@"aaaaaaaaa aaaa %@", p1);
label.text = p1.pLabel;

私のボタンコード:私は(null)を取得しました

 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    Slide *s1 = [appDelegate.books objectAtIndex:0];
    NSLog(@" test %@", s1.sLabel);

マイオブジェクトクラスのプレゼンテーションリンク

マイオブジェクトクラススライドリンク

私のXMLファイル

4

3 に答える 3

1

問題はここにあります

if ([elementName isEqualToString:@"Presentation1Name"]) {
    appDelegate.books = [[NSMutableArray alloc] init];
    NSLog(@"The Prices Count");
}

そのようなタグ (Presentation1Name) はなく、配列は作成されません。

于 2012-10-12T08:29:19.003 に答える
0

関数didStartElementでコードを変更します。このタグはありません'Presentation1Name'

if ([elementName isEqualToString:@"Presentation"]) {
    appDelegate.books = [[NSMutableArray alloc] init];
    NSLog(@"The Prices Count");
}

関数didEndElementでは、次の行を削除する必要があります。

[presentation setValue:currentElementValue forKey:@"pLabel"];

また、いくつかのメモリリークがあります。addObjectの後に解放する必要があります

if([elementName isEqualToString:@"Presentation"]) {
    [appDelegate.books addObject:presentation];
    [presentation release];
    presentation = nil;

}
if ([elementName isEqualToString:@"slide"]){
    [appDelegate.books addObject:slid];
    [slid release];
    slid = nil;
}

あなたはそれが役立つことを願ってリリースする必要があります。

于 2012-10-12T06:42:43.290 に答える
0

NULL 値を確認したい場合は、このコードを使用できます

[str isEqual:[NSNull null]

これは、その値が Web サービスからの NULL である場合に返されます。

これがお役に立てば幸いです!

于 2012-10-12T06:27:35.227 に答える