我正在从 UITableView 中的 URL 加载图像。但是加载 View 时它非常慢。这是一个例子,
UIImage *image = nil;
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://calcuttans.com/palki/wp-content/uploads/2009/02/kidscover-small.png"]]];
在 TableView 中,UIButton 正在设置背景图像。
请您提供 sample 。
仅供引用:我使用了 LazzyTable 示例程序,但它没有太大帮助。你能推荐任何其他 sample 吗?
最佳答案
异步加载图片
NSURL* url = [NSURL URLWithString:@"http://calcuttans.com/palki/wp-content/uploads/2009/02/kidscover-small.png"];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse * response,
NSData * data,
NSError * error) {
if (!error){
NSImage* image = [[NSImage alloc] initWithData:data];
// do whatever you want with image
}
}];
关于ios - 在 UITAbleView 中从 URL 加载图像缓慢。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14579079/