I’m trying to load an image into the cell,
The following code is working correctly :
NSString *imageURL = @"http://localhost/images/image2.jpg";
NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageURL]];
UIImage *rowImage = [[UIImage alloc] initWithData:imageData];
cell.image=rowImage;
but when i change imageURL to be dynamic , the image isn’t displayed :
NSString *imageURL = [[stories objectAtIndex:indexPath.row] objectForKey:@"image"];
You might be saying the problem is in :
[[stories objectAtIndex:indexPath.row] objectForKey:@"image"];
But it’s not , i’ve tried to log it and the output is as expected :
NSSLog(@"%@",[[stories objectAtIndex:indexPath.row] objectForKey:@"image"]);
//Outputs http://localhost/images/image2.jpg
What could be wrong ?
I am guessing there is space before or after the string. So do this,
While this should mostly fix your issue, I suggest you trim the strings before adding to the dictionary during the XML parsing.
You should also ensure you release both
imageDataandrowImage. You might be doing it already but its not in the code above so I just wanted to indicate that it could be leaking.