Reputation: 2408
I've the following view:
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:
Upvotes: 3
Views: 2603
Reputation: 2408
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!
Upvotes: 1