Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton not responding to touches

I've the following view:

enter image description here

The way it is build up

UIViewController --> UIView (bottom square) --> UIViewController (is loaded in the bottom square)

Button presses within in this UIViewController are not being triggered. However I do see the button animate when I press down in the simulator.

Also when I add the following tap handler programmatically to the round UIImageView in this UIViewController it responds:

func handleTap(sender: UITapGestureRecognizer? = nil) {
        print("tappable")
    }

let tap = UITapGestureRecognizer(target: self, action: #selector(NeighbourhoodViewController.handleTap(_:)))
userPopupView.userImageView.userInteractionEnabled = true
userPopupView.userImageView.addGestureRecognizer(tap)

How can I catch actions upon these buttons? This isn't working:

@IBAction func test(sender: AnyObject) {
        print("test")
    }

The line is connected to the UIButton in interface builder btw:

enter image description here

like image 700
Rutger Huijsmans Avatar asked Jan 31 '26 06:01

Rutger Huijsmans


1 Answers

I found the solution. I just had this to add the ViewController to the View:

self.popupView.addSubview(userPopupView.view)

When it should have been:

self.addChildViewController(userPopupView)
self.popupView.addSubview(userPopupView.view)
userPopupView.didMoveToParentViewController(self)

Now it works!

like image 173
Rutger Huijsmans Avatar answered Feb 02 '26 19:02

Rutger Huijsmans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!