如何异步下载多个图像在iOS中没有对UI的影响? [英] How to download multiple images asynchronously in iOS without effect on UI?

查看:91
本文介绍了如何异步下载多个图像在iOS中没有对UI的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有100个网址,我想下载所有这些图像和保存文档。为了节省我都做了,我也可以做延迟加载,但我无法用最少的时间下载所有和GUI不应该挂。

I have 100 URLs, I want to download all these images and save in Documents. For saving I have done, also I can do lazy loading, but I am unable to download all with minimum time and GUI should not hang.

什么是这样做合适的方法?

What is suitable method to do so?

感谢

推荐答案

使用SDWebImage。您可以从以下网址下载

Use SDWebImage. You can download it from below url

https://github.com/rs/SDWebImage

有关使用异步请求负载100的图像

For load 100 images using Asynchronous request

for(int i=0; i<99; i++)
{
    strImage=[[res valueForKey:@"result"] objectAtIndex:i];
    if ([[strImage lowercaseString] hasSuffix:@".jpg"] || [[strImage lowercaseString] hasSuffix:@".png"])
    {
        //[HUD show:YES];
        NSURL *url=[[NSURL alloc]initWithString:strImage];
        NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
        [NSURLConnection sendAsynchronousRequest:urlRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
        {
             thumbnail.image=[UIImage imageWithData:data];
        }];
    }
}

这篇关于如何异步下载多个图像在iOS中没有对UI的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆