I’ve created a simple XML-Parser to parse my rss Feeds to my app.
The id, currentstatus, picture of the simple to parse from the xml file.
But I can’t get the image from the XML file. . i retrieve the all the images from xml file. but the noimage.jpg not displaying. could you please any help me.
XML code
<Agent>
<id>3422</id>
<currentstatus>Logged Off</currentstatus>
<picture>1</picture>
</Agent>
<Agent>
<id>3432</id>
<currentstatus>Logged Off</currentstatus>
<picture>0</picture>
</Agent>
i tried the following code:
UIImage * cellimages = [[UIImage alloc]init];
NSString *string1 = @"http://telecomstats.co.uk/images/LLReaderProfile/";
NSString *cellvalue =[[[[self rssParser]rssItems]objectAtIndex:indexPath.row]picture];
NSString* disable = [[NSString alloc] initWithString:@"0"];
if (cellvalue == disable)
{
cellimages = [UIImage imageWithContentsOfFile:@"http://telecomstats.co.uk/images/LLReaderProfile/noimage.jpg"];
}
else {
cellimages = [string1 stringByAppendingString:[[[[self rssParser]rssItems]objectAtIndex:indexPath.row]id]];
cellimages = [cellimages stringByAppendingString: @".jpg"];
}
cellimages = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:cellimages]]];
cell.imageView.image = cellimages;
Does someone can help me?
Thanks for any help and insight.
You’re using
cellimageswhich is anUIImageobject to store strings in your else-branch. Also whencellvalue == disableis true, you execute this:There you put an
UIImagein[NSURL URLWithString:]which probably will not work; actually this code should produce quite some warnings. Try to properly separate between the URL string and the image object to display. Put all URL stuff in anNSStringand get theUIImageafterwards when you have determined the correct URL.Note that your code has some other problems, especially that you are using
dataWithContentsOfURLandimageWirhContentsOfFileboth of which will block until the image is retriebes. This will result in application hangs when using a bad internet connection and if the network is too slow, will crash your app. Have a look into asynchronous downloads and using frameworks like AFNetworking.