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 <
Create the outlet of your UIButton in UICollectionViewCell, write In
func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
cell.button.tag = indexPath.row
cell.button.addTarget(self,
action: #selector(self.yourFunc(),
for: .touchUpInside)
}
func yourFunc(sender : UIButton){
print(sender.tag)
}
Make sure userInteraction is enable for the button as well as for UICollectionViewCell.