1

_pageImages is nsmutableArry I'm store the image url.

_pageImages = [[NSMutableArray alloc]initWithObjects:@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com",@"https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com", nil];

Want to display this url images in uiimageview.

NSURL *url = [NSURL URLWithString:[_pageImages objectAtIndex:i]];

NSData *data = [[NSData alloc] initWithContentsOfURL:url];

UIImage *tmpImage = [UIImage imageWithData:data];

_backgroundImageView.frame = CGRectMake(0 ,10, 320, 320);

 _backgroundImageView.image = tmpImage;

  [self.view addSubview:_backgroundImageView];

I saw many examples but i can't get the proper solution. new for development. help me..

Saravananr
  • 21
  • 5
  • 2
    Did you checked that your data is not nil ? Cause maybe you just forget to disable App Transport Security for the target domain ( and when I try https://api.url2png.com/v3/P4DE5D1C99D8EF/7bbb6e0d1b74fb0ae1d4f18b06320096/400x400/abc.com myself, i get an error in browser ... ) – CZ54 Mar 14 '16 at 09:32
  • Yeah how about using methods that return `NSError` objects (for example `initWithContentsOfURL:options:error:`). – trojanfoe Mar 14 '16 at 09:34
  • you can find the anser here http://stackoverflow.com/questions/30096806/load-uiimage-from-url-in-ios – Ahd Radwan Mar 14 '16 at 09:34
  • check that your image URL , it shows at wrong – Anbu.Karthik Mar 14 '16 at 09:38
  • i change the url but still the is there UIImage *tmpImage = [UIImage imageWithData:data];... tmpImage is return null.. – Saravananr Mar 14 '16 at 09:49
  • _backgroundImageView.image = tmpImage; is null – Saravananr Mar 14 '16 at 09:53

3 Answers3

0

try this by sending AsynchronousRequest for image downloading--

NSURL *url = [NSURL URLWithString:[_pageImages objectAtIndex:i]];

[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:url] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    _backgroundImageView.image = [UIImage imageWithData:data];
}];
Rohit Khandelwal
  • 1,778
  • 15
  • 23
0

The problem is in the URL!

Try to access your images URL, all I got is "Unauthorized".

Run this sample code, your code, just using a different image address. Check for the correct image address, and it should run as expected.

NSMutableArray *pageImages = [[NSMutableArray alloc]initWithObjects:@"http://findicons.com/files/icons/1636/file_icons_vs_3/128/url.png",@"http://findicons.com/files/icons/1636/file_icons_vs_3/128/pdf.png", nil];

NSURL *url = [NSURL URLWithString:[pageImages objectAtIndex:0]];

NSData *data = [[NSData alloc] initWithContentsOfURL:url];

UIImage *tmpImage = [UIImage imageWithData:data];

_depImage.frame = CGRectMake(0 ,10, 320, 320);
_depImage.image = tmpImage;
Ulysses
  • 2,281
  • 1
  • 16
  • 24
0

We can simply use following to Load Image data from URL

_backgroundImageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLwithString:urlString]]];

No need of Calling a service call here.

Hope it helps..

Balaji Ramakrishnan
  • 1,909
  • 11
  • 22