简体   繁体   English

iOS未更新标签文字

[英]iOS not updating label text

I'm parsing xml here and am wondering why this is not working. 我在这里解析xml,想知道为什么这不起作用。 In my request object, I do this 在我的请求对象中,我这样做

- (Request *)performRequest{
NSError *error;
CXMLDocument *parser = [[CXMLDocument alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://production.shippingapis.com/ShippingAPITest.dll?API=TrackV2&XML=%3CTrackRequest%20USERID=%22827ACSTU1155%22%3E%3CTrackID%20ID=%22EJ958088694US%22%3E%3C/TrackID%3E%3C/TrackRequest%3E"] options:0 error:&error];
if (error) {
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"An error has occured. Try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}
NSArray *arr = [parser nodesForXPath:@"//TrackResponse/TrackInfo/TrackSummary" error:nil];
self.keyVal = [arr objectAtIndex:0];
NSLog(@"%@", keyVal);

return self;
}

the nslog is showing nslog显示

<CXMLElement 0x2005c7c0 [0x2005cfb0] TrackSummary <TrackSummary>Your item was delivered at 1:39 pm on June 1 in WOBURN MA 01815.</TrackSummary>>

which I expect. 我期望的。 However, in my view controller, I do this. 但是,在我的视图控制器中,我这样做。

- (void)viewDidLoad{
Request *re = [[Request alloc]init];
[re performRequest];
[self performSelectorOnMainThread:@selector(updateUI:) withObject:re waitUntilDone:NO];
}

- (void)updateUI:(Request *)re{
self.info1.text = re.keyVal;
NSLog(@"%@", re.keyVal);
}

however, the label (info1) and the log show (null). 但是,标签(info1)和日志显示(null)。 Why is this? 为什么是这样?

我将标题中的属性声明为:

(nonatomic, retain)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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