I am trying to set a click event on my UIStackview to open a viewcontroller. When I do this nothing happens. It doesn’t even print the line when I tap it. I tried multiple solutions on this website, like UITapGestureRecognizer but to no avail. What am I doing wrong?
My code:
private let stackUIView: UIView = {
let stackUIView = UIView(frame: CGRect(x: 25, y: 25, width: 400, height: 90))
let tap = UIGestureRecognizer(target: self, action: #selector(stackviewClicked))
stackUIView.addGestureRecognizer(tap)
stackUIView.isUserInteractionEnabled = true
return stackUIView
}()
@objc
func stackviewClicked() {
print("UIView Clicked")
let testVC = testViewController()
navigationController?.pushViewController(testVC, animated: true)
}
2
Answers
It should be
UITapGestureRecognizer
notUIGestureRecognizer
For me works, thanks