2010-06-20 79 views

回答

3

您可以使用NSDatadataWithContentsOfURL:类的方法来从服务器下载图像数据,然后只是数据传递给UIImageimageWithData:类方法。

下面是一个例子:

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://sstatic.net/so/apple-touch-icon.png"]]; 

UIImage *downloadedImage = [UIImage imageWithData:imageData]; 

myImageView.image = downloadedImage; 
+0

在后台工作的那个方法,或是否阻止当前线程? – dontWatchMyProfile 2010-06-20 09:29:35

+0

它阻止。如果您需要异步请求,请使用'NSURLConnection' – 2010-06-20 09:33:52

+0

它如何处理连接问题?返回零? – VdesmedT 2010-10-31 11:09:44