如何在iphone的UIImageView上从远程服务器加载图像?
我正在尝试从我的应用程序中的UIImageView上的远程服务器加载图像。是否可以从远程服务器加载图像。我使用以下代码
I am trying to load image from a remote server on the UIImageView in my application. Is it possible to load image from a remote server. I am using the following code
id path = @"http://upload.wikimedia.org/wikipedia/commons/c/c7/Sholay-Main_Male_Cast.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
我在网上发现这个代码是sippnet,但我不明白如何在ImageView。
I found this code sippnet on the net, but I dont understand how do I load this image on the ImageView.
任何人都可以告诉我如何在UIImageView上添加图片。
Can anyone tell me how to add image on the UIImageView.
提前完成Thanx ...
Thanx in advance...
你几乎一直在那里......现在只是
you got almost all the way there... now just
imageView.image = img;
请注意,使用 dataWithContentsOfURL
会阻止您的用户图像加载时的界面,如果你在启动时加载小图像,它将起作用,但通常是一个坏主意;查看 NSURLConnection
。
note that using dataWithContentsOfURL
will block your user interface while the image loads, which will work if you're loading small images at startup, but is generally a bad idea; look into NSURLConnection
.