Show image from url in uiimageview
I am trying to show an image in my iphone application but it is not showing. I am connecting in IB and I am checking to show the local image, this is good. I also check the url from the image and everything is fine. I am using the following code:
NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
imageView.image = image;
and
//Video.h
NSString *urlThumbnail;
and this is my code in view.
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"URLTHUMBNAIL: %@", aVideo.urlThumbnail);
NSURL *imageURL = [NSURL URLWithString: aVideo.urlThumbnail];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
imageView.image = image;
}
NSLog getts on console
URLTHUMBNAIL: http://147.83.74.180/thumbnails/56.jpg
Connections on IB are ok because I can display a local image using the following code on the same IBAction
UIImage *img = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"barret" ofType:@"png"]];
a source to share
First of all, since it is NSData dataWithContentsOfURL:
accessing the network, you should think about it in the background. Otherwise, your user interface may become unresponsive.
You should consider adding an additional log to validate the imageData
and values image
. Alternatively, you can call NSData dataWithContentsOfURL:options:error:
to find out if the source is a failure.
a source to share