How to add uibutton action in a collection view cell?

后端 未结 5 1039
走了就别回头了
走了就别回头了 2021-01-03 01:03

So I have this collection view with cells containing an edit button, located on the upper right corner. How do I wire up an action into it?

I tried adding <

5条回答
  •  执笔经年
    2021-01-03 01:24

    protocol CollectionViewCellDelegte {
        func collectionViewCellDelegte(didClickButtonAt index: Int)
    }
    
    class ImageCollectionViewCell: UICollectionViewCell {
        var index = 0
        var delegte: CollectionViewCellDelegte? = nil
    
        @IBAction func buttonAction(_ sender: UIButton) {
            if let del = self.delegte {
                del.collectionViewCellDelegte(didClickButtonAt: index)
            }
        }
    }
    

提交回复
热议问题