Uibutton in Cell in Collection View Not Receiving Touch Up Inside Event

not work UIButton from UICollectionViewCell

Try this :

Solution 1

In ViewController

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reviewAverageRateCellid, for: indexPath) as! ReviewAverageRate
cell.detailControllr = self
cell.giveReviewBtn.addTarget(self, action: #selector(self.giveReviewBtnTarget), for: .touchUpInside)
return cell
}

func giveReviewBtnTarget() {
// add your code

}

Solution 2

In cell class

            btn.addTarget(self, action: #selector(self.giveReviewBtnTarget), for: .touchUpInside)

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.

UIButton does not function in collectionView cell

I believe, to get your button action / target to register correctly, you need to declare them as lazy:

lazy var flipToBack: UIButton = {

lazy var flipToFront: UIButton = {

That should solve the tap issue.

Why is my touch up inside event for my UIButton not being called?

Aha, I got it. It turns out the subview which contained the button (along with the other controls) had a height of 740 and the button was at a Y of 781. Moving the button up fixed the issue. Since everything was displaying correctly, I didn't think to check the subview's height.



Related Topics



Leave a reply



Submit