Reputation: 53
I'm attempting to make a gesture recognizer in XCode, so that I can tap on my MKMapView and preform some actions. However, I am receiving the "unrecognized selector sent to instance" whenever I long-press the map.
Here is my code in viewDidLoad:
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: "handleTap:");
self.mapViewPlace.addGestureRecognizer(gestureRecognizer);
And here is the function later on:
func handleTap(gestureReconizer: UILongPressGestureRecognizer) {
}
Any ideas?
Upvotes: 5
Views: 2825
Reputation: 4919
By default Swift generates code that is only available to other Swift code, but if you need to interact with the Objective-C runtime – all of UIKit, for example – you need to tell Swift what to do.
So just add it and modify selector declaration:
@objc func handleTap(gestureReconizer: UILongPressGestureRecognizer) {
...
}
...
let swipe = UISwipeGestureRecognizer(target: self, action: #selector(handleTap(gestureReconizer:)))
Upvotes: 0
Reputation:
Please, give Neo credit. You need to change your syntax to this:
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleTap)
Side note: For Swift you do not need semi-colons the end your code lines.
Upvotes: 7