thelearner
thelearner

Reputation: 1136

UITapGestureRecognizer: "Unrecognized selector sent to instance"

I know this question has been asked a lot in the past, but almost all answers are either outdated (Obj c) or they don't seem to work for me.

When I try to click on my view I get following exception:

2018-02-05 12:18:30.162887+0100 Shay[28239:1248348] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[UIView tabClicked:]: unrecognized selector sent to instance 0x7f88edd02240'

This is my implementation:

//setting up the basic properties and adding Tap gesture
init(view: UIView,index: Int, tabHandler: TabHandler,  tabType: TabType) {

    ....

    //TapRecognizerAction
    let tap = UITapGestureRecognizer(target: rootView, action: #selector(  tabClicked(_:) ))
    tap.delegate = self as UIGestureRecognizerDelegate
    rootView.addGestureRecognizer(tap)

}

@objc public func tabClicked(_ recognizer: UITapGestureRecognizer){
print("WORKING")

}

Thanks a lot for helping a newbie!

Upvotes: 1

Views: 973

Answers (1)

Shehata Gamal
Shehata Gamal

Reputation: 100503

tabClicked should be in rootView implementation not in self.view

you can try

  let tap = UITapGestureRecognizer(target: self , action: #selector(  tabClicked(_:) ))

OR

extension UIView
{

 @objc public func tabClicked(_ recognizer: UITapGestureRecognizer){
    print("WORKING")

    }
}

Upvotes: 2

Related Questions