开发者

Loading image from URL on iPhone

I have no idea why this isn't working.

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

imageView is an 开发者_Go百科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.


Try this:

NSURL *url = [NSURL URLWithString: @"http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png"];

NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:data];
[imageView setImage:image]; 
//or imageView.Image=image;


Is your data being freed before it got assigned?

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];


You need to use NSURL. Follow this url http://iosdevelopertips.com/cocoa/download-and-create-an-image-from-a-url.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜