美文网首页
UICollectionViewCell防止重用

UICollectionViewCell防止重用

作者: 雷霸龙 | 来源:发表于2019-07-31 16:56 被阅读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
    }

相关文章

网友评论

      本文标题:UICollectionViewCell防止重用

      本文链接:https://www.haomeiwen.com/subject/vtvtdctx.html