Swift UITapGestureRecognizer

71 views Asked by At

For some reason, I can't get my gesture recognizer to work. The following line of code is executed in the viewDidLoad method:

self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.segmentTapped(sender:))))

The following is the method associated with the gesture:

 func segmentTapped(sender: UITapGestureRecognizer) {
    print("called")
 }

When the code is executed, "called" does not print in the console when the view is tapped. Gesture recognizers have always worked for me in the past, and I am confused as to what is going wrong.

1

There are 1 answers

0
Rehaan Advani On

Thanks you everyone who tried to help! The solution to this problem was quite simple. I simply deleted the app, reinstalled it, and the tap gesture worked as intended.