I'm trying to load an image from an image URL. All the code I have researched and tried finds a few errors, a lot having to do with new ARC compatibility.
I need the image to load into an image view.
Any help appreciated.
Thanks.
I'm trying to load an image from an image URL. All the code I have researched and tried finds a few errors, a lot having to do with new ARC compatibility.
I need the image to load into an image view.
Any help appreciated.
Thanks.
I will just adapt Jim Dovey answer from here Getting Image from URL Objective C :
Synchronous version
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://myurl/mypic.jpg"]];
UIImageView *imView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: imageData]];
Asynchronous version
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://myurl/mypic.jpg"]];
if ( data == nil )
return;
dispatch_async(dispatch_get_main_queue(), ^{
UIImageView *imView = [[UIImageView alloc] initWithImage:[UIImage imageWithData: data]];
});
});
UIImage *image = [UIImage imageWithContentsOfURL:[NSURL URLWithString:@"http://i.imgur.com/ytxO16A.png"];