Tag: uicollectionview

UICollectionView将图像添加到单元格

我正在使用UICollectionView来显示可能有或没有图像的数据的项目。 我使用的方式是检查图像的URL不是null,然后将一个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 ,会看到一些图像显示为上面显示的图像,然后在加载完成后切换到正确的图像,我不知道是什么导致了问题。 请帮我解决这两个问题,我真的很感激任何帮助。

UICollectionView设置列数

我刚开始学习UICollectionViews。 我想知道如果有人知道如何指定一个collectionview中的列数。 默认设置为3(iPhone /人像)。 我已经看了文档,似乎无法find一个简洁的答案。

UICollectionView – dynamic细胞高度?

我需要显示一堆具有不同高度的collectionViewCells。 意见太复杂,我不想手动计算预期的高度。 我想执行自动布局来计算单元格高度 调用cellForItemAtIndexPath之外的cellForItemAtIndexPath会破坏collectionView并导致崩溃 另一个问题是单元格不在单独的xib中,所以我不能手动实例化一个临时的单元格并将其用于高度计算。 任何解决scheme? public func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { var cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellIdentifier, forIndexPath: indexPath) as UICollectionViewCell configureCell(cell, item: items[indexPath.row]) cell.contentView.setNeedsLayout() cell.contentView.layoutIfNeeded() return cell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize) } 编辑: 一旦调用dequeueReusableCellWithReuseIdentifier,就会发生崩溃。 如果我不调用这种方法,而是返回一个大小,一切都很好,单元格显示没有计算的大小 stream布局中不支持负值或零大小 2015-01-26 18:24:34.231 [13383:9752256] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index […]

targetContentOffsetForProposedContentOffset:withScrollingVelocity无子类化UICollectionViewFlowLayout

我的应用程序中有一个非常简单的collectionView(只是一行方形缩略图)。 我想拦截滚动,以便偏移总是在左侧留下完整的图像。 此刻它滚动到任何地方,并会留下切断的图像。 无论如何,我知道我需要使用该function – (CGPoint)targetContentOffsetForProposedContentOffset:withScrollingVelocity 要做到这一点,但我只是使用标准的UICollectionViewFlowLayout 。 我没有inheritance它。 有没有任何方法来拦截这个没有UICollectionViewFlowLayout ? 谢谢