Ios 从cellForItemAtIndexPath中重新加载UICollectionViewCell
在cellForItemAtIndexPath中重试失败的映像下载的最佳方法是什么?我有一个集合视图,可以显示大约20个80x80缩略图。我使用cellForItemAtIndexPath方法下载和缓存图像,但我发现图像常常无法下载。我知道我可以使用完成块测试图像是否为零,但它似乎没有正确地重新加载图像(图像仍然不会显示)。我应该这样处理重新装入电池的问题吗?下面是我的代码示例Ios 从cellForItemAtIndexPath中重新加载UICollectionViewCell,ios,uicollectionview,uicollectionviewcell,sdwebimage,uicollectionreusableview,Ios,Uicollectionview,Uicollectionviewcell,Sdwebimage,Uicollectionreusableview,在cellForItemAtIndexPath中重试失败的映像下载的最佳方法是什么?我有一个集合视图,可以显示大约20个80x80缩略图。我使用cellForItemAtIndexPath方法下载和缓存图像,但我发现图像常常无法下载。我知道我可以使用完成块测试图像是否为零,但它似乎没有正确地重新加载图像(图像仍然不会显示)。我应该这样处理重新装入电池的问题吗?下面是我的代码示例 - (UICollectionViewCell *)collectionView:(UICollectionView
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
NSURL *thumbnailURL = [NSURL URLWithString:url];
INCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
[cell.imageView setImageWithURL:thumbnailURL completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
if (!image) {
[self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
}
}];
return cell;
}
有答案吗
您需要使用带有“options”参数和
指定SDWebImageRetryFailed,如下所示
[cell.imageView setImageWithURL:thumbnailURL占位符图像:[UIImage]
ImageName:@“placeholder.png”]选项:SDWebImageRetryFailed
已完成:^(UIImage*图像,NSError*错误,SDImageCacheType
cacheType){…}]