[英]Reload cell of CollectionView after image is downloaded
I'm using the library SDWebImage to download the images. 我正在使用SDWebImage库下载图像。
I set the image downloaded to the UICollectionViewCell inside cellForItemAtIndexPath but the image is visible just after scrolling the CollectionView. 我将下载的图像设置为cellForItemAtIndexPath内的UICollectionViewCell,但是在滚动CollectionView之后才可见该图像。 I think that I must reload that specific cell but no idea how.
我认为我必须重新加载该特定单元,但不知道如何加载。
Here is the code of UICollectionViewCell 这是UICollectionViewCell的代码
[imgView setImageWithURL:[NSURL URLWithString:imgUrl]
placeholderImage:[UIImage imageNamed:@"YourPlaceholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {
//... completion code here ...
cell.image = imgView.image;
//Reload The cell to see the image downloaded ¿HOW?
}];
code of MJCollectionViewCell.m MJCollectionViewCell.m的代码
- (void)setImage:(UIImage *)image
{
// Store image
self.MJImageView.image = image;
// Update padding
[self setImageOffset:self.imageOffset];
}
Any idea how to solve it? 知道如何解决吗?
I encountered this same problem. 我遇到了同样的问题。
The solution: [cell setNeedsLayout]; 解决方法:[cell setNeedsLayout];
have you tried doing something like this? 您是否尝试过做类似的事情?
dispatch_async(dispatch_get_main_queue(), ^{
cell.image = imgView.image;
});
or reloading using - (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths
like 或使用
- (void)reloadItemsAtIndexPaths:(NSArray *)indexPaths
重新加载
[collectionView reloadItemsAtIndexPaths:YourIndexPath];
You have to upgrade SDWebImage, your version doesn't work with iOS8. 您必须升级SDWebImage,您的版本不适用于iOS8。 Download the last library of SDWebImage and use sd_setImageWithURL method instead.
下载SDWebImage的最后一个库,并改用sd_setImageWithURL方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.