Collection View Cell Button Not Triggering Action

Button inside CollectionView not clickable

After searching the entire web pretty much, I finally found the solution that was in the comment of this SO answer: https://stackoverflow.com/a/44908916/406322

I needed to add this in MyCollectionViewCell:

self.contentView.isUserInteractionEnabled = false

I think the cell selection was hijacking the touch event.

buttons not showing in collectionviewcell swift

The action syntax is wrong.

Change addTarget(_:action:for:) to

cell.buttonOne.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)

and the corresponding method to

@objc func didTapButton(_ sender: UIButton) {

Radio Button Not Working In ColectionView Cell , If I select One Button another Buttons aren't Deselecting

If you want to only one can be selected , you could basically do this :

@objc func logoButtonTapped(sender: UIButton){
let index = sender.tag
selection.removeAll()
selection.append(index)
self.teamCollectionView.reloadData()
}

This condition (selection.contains(index)) only works when index is a part of selection array so when you add new one , old one won't gonna remove



Related Topics



Leave a reply



Submit