【发布时间】:2014-07-11 04:07:20
【问题描述】:
我正在做一个项目,该项目使用UICollectionView 来显示可能有也可能没有图像的数据。
我使用的方式是检查图片url是否不为空,然后在单元格上添加一个ImageView。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (question.picture != (id)[NSNull null]) {
//add AsyncImageView to cell
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
imageView.tag = IMAGE_VIEW_TAG;
[cell addSubview:imageView];
[[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:imageView];
imageView.imageURL = [NSURL URLWithString:question.picture];
}
}
对于那些没有图像的单元格,单元格应如下所示: https://dl.dropboxusercontent.com/u/5753236/Stackoverflow/good.png
然而,他们中的一些人仍然会添加一个带有裁剪图像的 ImageView,导致如下所示: https://dl.dropboxusercontent.com/u/5753236/Stackoverflow/bad.png
我尝试过使用 SDWebImage,但仍然没有解决问题。
另一个问题是当我向下滚动UICollectionView时,我会看到一些图像首先显示为上图所示的图像,然后在加载完成后更改为正确的图像,我只是不知道是什么导致问题。
请帮我解决这两个问题,非常感谢您的帮助。
【问题讨论】:
-
你的链接不好
标签: ios uiview uiimage uicollectionview uicollectionviewcell