从iPhone上的URL加载图像 [英] Loading image from URL on iPhone

查看:63
本文介绍了从iPhone上的URL加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么这不起作用.

I have no idea why this isn't working.

NSData *data = [NSData dataWithContentsOfURL:place.iconData];
UIImage *image = [UIImage imageWithData:data];
[imageView setImage:image];

imageView是通过IB连接的IBOutlet.place.iconData是 http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png .但是由于某种原因,它不会加载.非常感谢您的帮助.

imageView is an IBOutlet hooked up through IB. place.iconData is http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png. For some reason, though, it won't load. Any help is much appreciated.

推荐答案

在分配数据之前是否已将其释放?

Is your data being freed before it got assigned?

也许尝试为NSData手动分配内存:

Maybe try manually allocating memory for the NSData:

NSData *data = [[NSData alloc] initWithContentsOfURL:place.iconData];
UIImage *image = [[UIImage alloc] initWithData:data];
[imageView setImage:image];

[data release];
[image release];

这篇关于从iPhone上的URL加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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