Swift:Gesture Recognizer无法识别的选择器发送到实例 [英] Swift: Gesture Recognizer unrecognized selector sent to instance
本文介绍了Swift:Gesture Recognizer无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在XCode中制作手势识别器,以便我可以点击我的MKMapView并执行一些操作。但是,每当我长按地图时,我都会收到无法识别的选择器发送到实例。
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.
这是我在viewDidLoad中的代码:
Here is my code in viewDidLoad:
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: "handleTap:");
self.mapViewPlace.addGestureRecognizer(gestureRecognizer);
以下是此功能:
func handleTap(gestureReconizer: UILongPressGestureRecognizer) {
}
任何想法?
推荐答案
请给予Neo信用。您需要将语法更改为:
Please, give Neo credit. You need to change your syntax to this:
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(handleTap)
附注:对于Swift,你的代码行不需要分号。
Side note: For Swift you do not need semi-colons the end your code lines.
这篇关于Swift:Gesture Recognizer无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文