Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SDWebImage正在下载但不显示图像_Ios_Objective C_Uicollectionview_Sdwebimage - Fatal编程技术网

Ios SDWebImage正在下载但不显示图像

Ios SDWebImage正在下载但不显示图像,ios,objective-c,uicollectionview,sdwebimage,Ios,Objective C,Uicollectionview,Sdwebimage,我正在使用UICollectionView 图像来自FTP服务器。 以下是我下载并在按钮上显示图像的代码: [tempp sd_setImageWithURL:[NSURL URLWithString:[[arrFilterData objectAtIndex:indexPath.row] valueForKey:@"ZoomPrdImg"]] //PrdImg //ZoomPrdImg placeholderImage:nil

我正在使用
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];
}
替换

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


因为在您的完成处理程序中,您将在
image
object

中获取图像,我认为您的变量tempp被破坏,并取消对图像的请求。 将请求代码更改为

[myButton sd_setImageWithURL:[NSURL URLWithString:@"MyURL"] forState:UIControlStateNormal completed:yourCompletitionBlock];
一切都会好起来的

UPD

根据您对tempp变量的回答,我认为您每页可以看到一个图像,因为当您调用sd_setImage。。。对于许多单元格,只有最后一个请求正在加载。请求是异步的,如果您请求新映像,旧请求将被取消

来自SDWebImage的代码:

- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
    [self sd_cancelCurrentImageLoad];
    objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

第一行取消旧请求

你能解释一下这一行中的tempp.image是什么吗[myCell.image setImage:tempp.image forState:UIControlStateNormal];正如我在我的quen myCell.image中提到的那样,我将下载的图像设置到了我的按钮中。在分配给按钮时,将tempp.image更改为image使用占位符图像,而不是使用
NIL
,并确保您的图像url是正确的。我已经尝试过了,但同样的问题。@MuhammadWaqasBhati和@nitingohelthel检查
错误
从那个完成处理程序。因为你没有得到图像,所以我想没有,没有错误,它成功下载了。sd_setImageWithURL可以工作,但它在一段时间后崩溃,例外情况是:CoreFoundation`CFGetTypeID:-----------如何摆脱它?我认为您使用的方法不正确,能否显示新代码?哪些代码?我从ftp服务器上获取图像,所以它有什么问题吗?你不应该使用tempp,而应该使用myCell.image。使用tempp是主要的错误,另一个也没那么糟糕。
- (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
    [self sd_cancelCurrentImageLoad];
    objc_setAssociatedObject(self, &imageURLKey, url, OBJC_ASSOCIATION_RETAIN_NONATOMIC);