When I tap on button it will trigger multiple times.
CollectionViewCell file code
class PhotoCell: UICollectionViewCell {
@IBOutlet weak var deleteButton: UIButton!
}
ViewController - cellforItemAt method implementation
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PhotoCell", for: indexPath) as? PhotoCell else { return UICollectionViewCell() }
let action = UIAction { _ in
print("Delete button tapped!!!", indexPath.row)
}
cell.deleteButton.addAction(action, for: .touchUpInside)
return cell
}
If I configure UIButton addTarget then it work fine but I am not sure why it's not working with addAction.