I am new to iPhone.Im my application i want getting image from url
I tried the fallowing code
-(void)viewDidLoad
{
UIImageView *UV=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:UV];
NSURL *url = [NSURL URLWithString:@"http://www.google.com/recaptcha/api/noscript?k=6LdON9USAAAAAO9AtfFsuLxBY1l-yNDBoJcb1Jeb"];
NSData *myData = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:myData];
UV.image=image;
}
but image is not displayed in image view .can any one help to me
thanks in advance
The URL you give isn’t an image so it won’t work.
More importantly, while it looks OK, it’s absolutely not recommended to do it like this.
The call to
dataWithContentsOfURL:is blocking the main thread during the download, making the app unresponsive.Take a look at some open-source projects as mentioned by Antaresm.
You may also want to look at AFNetworking, put it in your project and then, all you have to write is