I fixed this on my own by declaring the property in the header as
(nonatomic, retain)
سؤال
I'm parsing xml here and am wondering why this is not working. 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
<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). Why is this?
المحلول
I fixed this on my own by declaring the property in the header as
(nonatomic, retain)