SdWebImage 问题中的活动指示器

Raj*_*ari 3 objective-c uiactivityindicatorview ios sdwebimage uicollectionview

我有一个水平集合视图,它有 20 个带有 UIImageView 的单元格我只想显示活动指示器,直到图像下载完成。我正在使用新的 SDWebImage 库,其中我们的方法为sd_setImageWithURL 直到现在我正在做的是

__block UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center = cell.photoOneImageView.center;
activityIndicator.hidesWhenStopped = YES;

[cell.photoOneImageView sd_setImageWithURL:[NSURL URLWithString:@"https://scontent-sjc.xx.fbcdn.net/hphotos-xpa1/v/t1.0-9/p480x480/11073324_10153728863852926_4010319763478440264_n.jpg?oh=590934059508b7da235a46fc39e08063&oe=55B61458"] 
placeholderImage:[UIImage imageNamed:@"placeholder.jpg"] 
completed:^(UIImage *image, NSError *error,  SDImageCacheType cacheType, NSURL *imageURL) {
    [activityIndicator stopAnimating];
    [activityIndicator removeFromSuperview];
    }];

[cell.photoOneImageView addSubview:activityIndicator];
[activityIndicator startAnimating];
Run Code Online (Sandbox Code Playgroud)

我在cellForItemAtIndexPath方法中编写此代码它有时会在 1 个单元格上显示多个指标,有时当我们水平滚动集合视图时,它们也不会删除。

我看到了这个https://github.com/rs/SDNetworkActivityIndi​​cator但我无法使用它。没有运气。当图像完成指示器消失时,是否有人在 tebleview 单元格或集合视图单元格中实现了活动指示器。请帮忙。任何帮助将不胜感激。谢谢

Ank*_*pta 5

最好的方法是使用最新存储库中提供的 SDWebImage 的默认活动指示器

更新:SWIFT 5 SDWebImage 5.xx

        cell.imageView.sd_imageIndicator = SDWebImageActivityIndicator.gray
        cell.imageView.sd_setImage(with: url) { (image, error, cache, urls) in
            if (error != nil) {
                // Failed to load image
                cell.imageView.image = UIImage(named: "ico_placeholder")
            } else {
                // Successful in loading image
                cell.imageView.image = image
            }
        }
Run Code Online (Sandbox Code Playgroud)

快速3:

cell.imageView.setShowActivityIndicator(true)
cell.imageView.setIndicatorStyle(.gray)
cell.imageView?.sd_setImage(with: url) { (image, error, cache, urls) in
                if (error != nil) {
                    // Failed to load image
                    cell.imageView.image = UIImage(named: "ico_placeholder")
                } else {
                    // Successful in loading image
                    cell.imageView.image = image
                }
 }
Run Code Online (Sandbox Code Playgroud)