如何在iphone的UIImageView上从远程服务器加载图像? [英] How to load image from remote server on the UIImageView in iphone?

查看:101
本文介绍了如何在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.

这篇关于如何在iphone的UIImageView上从远程服务器加载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆