I load my XML in to my iphone app via:
NSArray *Images = [doc nodesForXPath:kName_logo error:nil];//Root node
for (CXMLElement *ImgIcons in Images)
{
NSArray *locImage = [ImgIcons elementsForName:kName_image];
for(CXMLElement *fullImage in locImage)
{
LocationImage = fullImage.stringValue;
locStatImage = LocationImage;
NSLog(@"Image Found %@",LocationImage);
break;
}
}
Which is fine, it’s bringing me back the correct string
2011-11-03 14:48:43.572 Del Search[13152:f203] Image Found http://de1128/directenquirieswebapplicationv3.0/images/logos/PremierInn.jpg
However, When I load it on to my table through the following:
if (indexPath.section == 0)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierImage];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifierImage] autorelease];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,180)];
imageView.tag = 1;
NSURL *Imageurl = [NSURL URLWithString:[NSString stringWithFormat:@"%@", locStatImage]];
NSData *data = [NSData dataWithContentsOfURL:Imageurl];
UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];
imageView.image = img;
[cell addSubview:imageView];
[imageView release];
}
return cell;
}
The app falls over. However if I manually set locStatImage by doing:
locStatImage = @"http://de1128/directenquirieswebapplicationv3.0/images/logos/PremierInn.jpg";
It works fine. What’ am I doing wrong when I set locStatImage?
Thanks
Tom
Assuming the two code snippets above are from separate methods,
locStatImageis probably being autoreleased between you obtaining it from the XML and using it in your cellForRowAtIndexPath method.Further assuming
locStatImageis a retained property (if it isn’t it should be), in your first code sample you should use