在UITAbleView中缓慢加载URL中的图像.

2vi*_*on2 0 objective-c uitableview ios

我正在UITableView中从URL加载图像.但是加载视图时速度很慢.这是一个例子,

UIImage *image = nil;
image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://calcuttans.com/palki/wp-content/uploads/2009/02/kidscover-small.png"]]];
Run Code Online (Sandbox Code Playgroud)

在表视图中,UIButton我正在设置背景图像.

请您提供样品.

仅供参考:我使用的是LazzyTable示例程序,但它没什么用处.你能建议任何其他样品吗?

Mad*_*man 17

异步加载图像

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
    }

}];
Run Code Online (Sandbox Code Playgroud)