简体   繁体   English

使用SDWebimage,使用url逐个下载图像

[英]Download Images One By One with url using SDWebimage

I need to Download images from Array of Url's, one by one and Display all at a Time. 我需要逐个从Url的Array中下载图像并一次显示所有图像。 Ex. 防爆。 I have an array of 10 URL's and I need to Download image One By One only, and display at a time. 我有一个10个URL的数组,我需要一个一个地下载图像,并一次显示。 I am Using SDWebImage for Download Images. 我正在使用SDWebImage下载图像。 Please Help me. 请帮我。

Thanks. 谢谢。

You can try something like this 你可以尝试这样的事情

-(void)downloadImage {
     if self.urlArray.count > 0) {
         NSURL *url = [NSURL URLWithString:[self.urlArray firstObject]];
         SDWebImageManager *manager = [SDWebImageManager sharedManager];
         [manager downloadImageWithURL:imageURL
                  options:0
                 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                     // progression tracking code
                 }
                 completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                     if (image) {
                         [self.imageArray addObject:image];
                         [self.urlArray removeObjectAtIndex:0];
                         [self downloadImage];
                     }
                     else {
                         [self downloadImage]; //try download once again
                     }
                 }];
     }
     else {
         NSLog(@"All Images are downloaded do what u want")
     }
} 

Note:- Here urlArray is array of string url and imageArray array contain all the image that you have download. 注意: -这里urlArray是字符串url的数组, imageArray数组包含你下载的所有图像。

call this method after you have got all the string url in urlArray . urlArrayurlArray所有字符串url后调用此方法。

Hope this will help you. 希望这会帮助你。

This is how you download image as independent image with SDWebImage in Swift 这是您在Swift中使用SDWebImage将图像作为独立图像下载的方式

import SDWebImage

let downloader = SDWebImageManager()

downloader.imageDownloader?.downloadImage(with: URL(string: imageUrl), options: .highPriority, progress: { 
        (receivedSize, expectedSize, url) in
        // image is being downloading and you can monitor progress here
            }, completed: { (downloadedImage, data, error, success) in
                print(downloadedImage, data, success)
                //image is downloaded and ready to use
            })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM