【问题标题】:Loading images in collectionView在 collectionView 中加载图像
【发布时间】:2018-04-03 19:39:03
【问题描述】:

每个UITableViewCell 都包含一个UICollectionView。无法弄清楚为什么某些 UICollectionViewCell 图像没有显示。我正在使用SDWebImage 库来加载图像。方法- (void)sd_setImageWithURL:(NSURL *)url调用[self sd_cancelCurrentImageLoad];。我认为取消先前的请求是问题所在,但请阅读会产生竞争条件的地方。每个UITableViewCell 都不会出现问题,如果我点击单元格获取详细信息并返回,图像会填充。也许我需要在某个地方重新加载数据。关于如何解决这个问题的任何提示?

【问题讨论】:

  • 您必须在cellForRowAtIndexPath: 中的tableView 中重新加载collectionView

标签: ios objective-c uitableview asynchronous uicollectionview


【解决方案1】:

如果您尝试从服务器获取图像来尝试此操作。

#import "UIImageView+WebCache.h"

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NewProfileCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];


[cell.img_user_image sd_setImageWithURL:[NSURL URLWithString:[mutDict valueForKey:@"UserImageURL"][indexPath.row]] placeholderImage:[UIImage imageNamed:@"No_IMAGE_PLACE"]];

return cell;
}

【讨论】:

    【解决方案2】:

    试试看:

    - (void)prepareForReuse
    {
        [super prepareForReuse];
        [self.imageView cancelCurrentImageLoad];
        [self.imageView setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal]; // Placeholder image
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-29
      • 2015-08-14
      • 2020-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多