简体   繁体   English

在collectionView中加载图像

[英]Loading images in collectionView

Each UITableViewCell contains a UICollectionView . 每个UITableViewCell包含一个UICollectionView Having trouble figuring out why some UICollectionViewCell images are not showing up. 无法弄清楚为什么未显示某些UICollectionViewCell图像。 I'm using SDWebImage library to load images. 我正在使用SDWebImage库加载图像。 The method - (void)sd_setImageWithURL:(NSURL *)url calls [self sd_cancelCurrentImageLoad]; 方法- (void)sd_setImageWithURL:(NSURL *)url调用[self sd_cancelCurrentImageLoad]; . I think cancelling the previous request is the problem, but read somewhere that will create a race condition. 我认为取消先前的请求是问题所在,但请阅读某个会产生竞争条件的地方。 Problem doesnt happen for every UITableViewCell , and if I tap on cell for details and go back, the images fill in. Perhaps I need to reload data somewhere. 每个UITableViewCell都不会出现问题,如果我点击单元格以获得详细信息并返回,则图像将填充。也许我需要在某个地方重新加载数据。 Any tips on how to solve this? 关于如何解决此问题的任何提示?
在此处输入图片说明

if you try to image fatch from server to try this. 如果您尝试从服务器上获取图像,则可以尝试这样做。

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

Try it: 试试吧:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM