iOS不更新标签文本

时间:2013-02-09 02:08:39

标签: iphone ios objective-c uilabel touchxml

我正在解析xml,我想知道为什么这不起作用。在我的请求对象中,我这样做

- (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;
}

nslog正在显示

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

我期待。但是,在我的视图控制器中,我这样做。

- (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);
}

但是,标签(info1)和日志显示(null)。这是为什么?

1 个答案:

答案 0 :(得分:0)

我通过将标题中的属性声明为

来自行修复此问题
(nonatomic, retain)