views:

61

answers:

2

I have a string variable tmpImgURLStr which contains URL like www.abc.com/img.png. i want to display that image in my imageView for that i have use some code but it's not working which is given below:

NSLog(@"Img URL === %@",tmpImgURLStr);

NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",tmpImgURLStr]]]; 

UIImage *myimage = [[UIImage alloc] initWithData:mydata];
[logoImg setImage:myimage];
+1  A: 

As far as I can tell from your url - you have pdf, not an image. Usually WebViews are used for displaying this sort of data.

Update

Your NSData initiation is kinda too long. You can actually initiate a URL without supplying formatted string:

NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:tmpImgURLStr]];

Also I've noticed that your URL is without protocol. You may want to try adding http:// or https:// to it and then see what happens. And just in case check if your logoImg is actually wired to the NSImageView in your NIB.

Eimantas
sorry it's printing Mistake by me....Thanks for Showing me....
Ankit Vyas
Yes your notice is perfectly right it's because of missing of http:// or https:// i have resolved it by adding this lines Thank you Very Much.
Ankit Vyas
A: 

Try this code instead of yours .. May be it will work..

logoImg=[[IUImageView alloc]initWithFrame:CGRectMake(10,10,300,460)];
NSLog(@"Img URL === %@",tmpImgURLStr);
NSData *mydata = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:tmpImgURLStr]]];
UIImage *myimage = [[UIImage alloc] initWithData:mydata];
[logoImg setImage:myimage];

-Happy coding....

Suriya