滚动后在集合视图中查看更新太晚了

时间:2016-10-26 08:50:03

标签: ios swift scroll uicollectionview

我在每个单元格中都有CollectionView图像。 当我滚动此集合时,新单元格(indexPath = 10)包含来自旧单元格的图像(indexPath = 1),然后调用此方法:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

}

我将图片网址设置为新视图。 在更新之前滚动后隐藏旧图像的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

重新使用它们时,需要清理CollectionViewCell中的图像。 覆盖CollectionViewCell子类中的prepareForReuse函数。

  override func prepareForReuse() {
        super.prepareForReuse()
        // Set the cell's imageView's image to nil
        self.imageView.image = nil
    }
相关问题