UICollectionViewCell防止重用

2019-07-31  本文已影响0人  雷霸龙
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let identifier = "cell"
        collectionView.register(RescueProjectCell.self, forCellWithReuseIdentifier: identifier)
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! RescueProjectCell
        // 此处可起到防止重用的作用
        for view in cell.contentView.subviews {
            view.removeFromSuperview()
        }
        
        return cell
    }
上一篇 下一篇

猜你喜欢

热点阅读