Reputation: 1297
Im experimenting on tap gestures
I'm trying to add a tap gesture to a view but when the click occurs I get an error
here is my code:
class ViewController: UIViewController {
@IBOutlet weak var myView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
myView.backgroundColor = UIColor.redColor()
let tapGestureRecognizer:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "TapPageHandler")
myView.addGestureRecognizer(tapGestureRecognizer)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func TapPageHandler(recognizer: UITapGestureRecognizer){
print("hello world")
}
}
and the error I get is:
2016-05-14 20:08:47.753 TapGestureTest[6641:245475] -[TapGestureTest.ViewController TapPageHandler]: unrecognized selector sent to instance 0x7fc1fb58f430 2016-05-14 20:08:47.813 TapGestureTest[6641:245475] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TapGestureTest.ViewController TapPageHandler]:
can anyone guide me through this? and tell why this happened?
Upvotes: 0
Views: 42
Reputation: 107201
You are having different selector signature and method signature (Your method signature expects a parameter and your selector signature expects a method with no parameter).
You need to specify the selector like:
let tapGestureRecognizer:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "TapPageHandler:")
Upvotes: 2
Reputation: 487
action: "TapPageHandler" should be action: "TapPageHandler:", the : defines that it will be expecting a argument.
Upvotes: 1