【问题标题】:Reload UICollectionViewCell from within cellForItemAtIndexPath从 cellForItemAtIndexPath 中重新加载 UICollectionViewCell
【发布时间】:2013-08-14 19:47:28
【问题描述】:

在 cellForItemAtIndexPath 中重试失败的图像下载的最佳方法是什么?我有一个可以显示大约 20 个 80x80 缩略图的集合视图。我正在使用SDWebImage 在 cellForItemAtIndexPath 方法中下载和缓存图像,但我发现图像经常无法下载。我知道我可以使用完成块并测试图像是否为零,但它似乎没有正确重新加载图像(图像仍然永远不会出现)。这是我应该如何处理重新加载单元格吗?这是我的代码示例。

- (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;
}

【问题讨论】:

    标签: ios uicollectionview uicollectionviewcell sdwebimage uicollectionreusableview


    【解决方案1】:

    github得到答案

    您需要使用带有“选项”参数的方法之一,并且 像这样指定 SDWebImageRetryFailed...

    [cell.imageView setImageWithURL:thumbnailURL placeholderImage:[UIImage imageNamed:@"placeholder.png"] 选项:SDWebImageRetryFailed 完成:^(UIImage *image, NSError *error, SDImageCacheType 缓存类型){...}];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-29
      相关资源
      最近更新 更多