除了使用方法uiimage
之外,如何从nsurl
获取NSData *data = [NSData dataWithContentsOfURL:url];
在nsthread
正在运行时,ui元素无法正常工作
答案 0 :(得分:1)
答案 1 :(得分:1)
来自Gowalla的AFNetworking库有一种在后台加载图像的简单方法。见here
答案 2 :(得分:0)
我喜欢使用ASIHttpRequest。它会是这样的。
ASIHTTPRequest * request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
NSData * responseData = [request responseData];
UIImage * image = [UIImage imageWithData:responseData];
}];
[request setFailedBlock:^{
NSLog(@"Failed to load image : %@", [request.error localizedDescription]);
}];
[request startAsynchronous];
答案 3 :(得分:0)
对于背景图片下载,您可以尝试
https://github.com/AFNetworking/AFNetworking/
答案 4 :(得分:0)
浏览此链接:http://www.markj.net/iphone-asynchronous-table-image/
下载
AsyncImageView.h AsyncImageView.m
将这些文件添加到您的项目中并将其导入您的课程
写下这些行,你想要添加imagesubview:
AsyncImageView * asyncImageView = [[AsyncImageView alloc] initWithFrame:CGRectMake(80,10,60,20);]; NSURL * url = [NSURL URLWithString:imageUrl]; [asyncImageView loadImageFromURL:url]; asyncImageView.backgroundColor = [UIColor clearColor]; [myimageView addSubview:asyncImageView]; [asyncImageView release];
你会得到