OStack程序员社区-中国程序员成长平台

标题: ios - SDWebImage 下载但不显示图像 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 16:37
标题: ios - SDWebImage 下载但不显示图像

我正在使用 UICollectionView

图片来自 FTP 服务器。 这是我在按钮上下载和显示图像的代码:

[tempp sd_setImageWithURL:[NSURL URLWithString:[[arrFilterData objectAtIndex:indexPath.row] valueForKey"ZoomPrdImg"]] //PrdImg //ZoomPrdImg
             placeholderImage:nil
                    completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                        if (image) {
                            myCell.image.userInteractionEnabled = YES;
                            dispatch_async(dispatch_get_main_queue(), ^{
                                [myCell.image setImage:image forState:UIControlStateNormal];
                                [myCell setNeedsLayout];
                            });
                        }
                    }];

myCell.image 是我设置下载图像的按钮。 现在我没有成功下载该图像,但按钮中显示了螺母。 UICollectionView 中有 3000 多张图像,但它显示了一些图像和一些空白。

这怎么可能?如何解决这个问题?有什么问题?

编辑: tempp 在 viewDidLoad

中分配
- (void)viewDidLoad {
    tempp = [[UIImageView alloc] init];
}



Best Answer-推荐答案


替换

 [myCell.image setImage:tempp.image forState:UIControlStateNormal];
                            [myCell setNeedsLayout];

 [myCell.image setImage:image forState:UIControlStateNormal];
                            [myCell setNeedsLayout];

因为在您的完成处理程序中,您正在 image 对象中获取图像

关于ios - SDWebImage 下载但不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37518441/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4