简体   繁体   中英

Setting UILabel text not working?

I have this XML parser class that needs to set the text of a UILabel. For some reason when I call my external (My external custom method is located in ViewController) custom method from the XML parsing class I cant change the labels text. Anything else like NSLogging works or an UIAlert works.
Code im trying to do it with:

-(void) parser:(NSXMLParser *) parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
    if([elementName isEqualToString:@"names"]){
        NSLog(@"Found names body");

    }
    else if ([elementName isEqualToString:@"user"]){

 array = [attributeDict objectForKey:@"nameofuser"];
        ViewController * main = [[ViewController alloc] init];
        [main outputToLabel:array];

    }
    NSLog(@"Reading value: %@", elementName);
}


This is my ViewController custom method:

-(void) outputToLabel:(NSArray *) dict{

    NSLog(@"seting %@ srcds", dict);
    // XML stuff here \/

NSLog(@"%@", dict);

       //                 /\

    this.text = @"Complete";
}

It NSLogs out the values correctly and everything... I just cant set the labels text. I can use that code in viewDidLoad and it works fine. Any ideas?

    ViewController * main = [[ViewController alloc] init];
    [main outputToLabel:array];

You're creating a new instance of your ViewController and setting the label in it. The "real" instance of ViewController is not affected by this action.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM