Reused cells in a UICollectionView show multiple UIImageViews when they should only show one

后端 未结 7 1856
天命终不由人
天命终不由人 2020-12-08 09:53

Im having a problem with my UICollectionView. Initially it displays fine, showing a grid of cells, each cell with a single UIImageView. These

7条回答
  •  情书的邮戳
    2020-12-08 10:41

    For those who are looking for a Swifty answer, add this function to your CustomCell class:

    override func prepareForReuse() {
        contentView.subviews.forEach({ $0.removeFromSuperview() })
        // replace contentView with the superview of the repeating content.
    }
    

提交回复
热议问题