在UITAbleView中缓慢加载URL中的图像。 [英] Slow loading the images from URL in UITAbleView.
本文介绍了在UITAbleView中缓慢加载URL中的图像。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在UITableView中从URL加载图像。但加载视图时速度很慢。这是一个例子,
I'm loading the images from URL in UITableView. But it's very slow when loading an view. Here's an example,
UIImage *image = nil;
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://calcuttans.com/palki/wp-content/uploads/2009/02/kidscover-small.png"]]];
在表格视图中,UIButton我正在设置背景图片。
In Table view, UIButton i'm setting the background image.
请您提供样品。
FYI:我使用的是LazzyTable示例程序,但它没什么用处。你能建议任何其他样品。
FYI : I'm used the LazzyTable sample program but it's not much helpful. Can you suggest any other samples.
推荐答案
异步加载图片
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
}
}];
这篇关于在UITAbleView中缓慢加载URL中的图像。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文