Swift 3 MKMapView - 长按添加图钉/注释

时间:2017-02-13 00:13:38

标签: ios swift xcode

我正在尝试设置MKMapView,以便当我按住地图2秒钟时,会在用户的当前位置显示一个图钉。

以下是我viewDidLoad中的内容:

let gestureRecognizer = UILongPressGestureRecognizer(target: self, action:(Selector(("longPress:"))))
gestureRecognizer.minimumPressDuration = 2.0
gestureRecognizer.delegate = self
map.addGestureRecognizer(gestureRecognizer)

然后在我的ViewController类的底部,我有以下内容:

func longPress(gestureRecognizer: UILongPressGestureRecognizer) {

    let coordinate = map.centerCoordinate

    let annotation = MKPointAnnotation()
    annotation.coordinate = coordinate
    map.addAnnotation(annotation)
}

当我运行应用程序并在地图上按住2秒钟时,应用程序崩溃了。控制台说

  

以NSException类型的未捕获异常终止


  

无法识别的选择器发送到实例0x7f89f0c02ad0

我不知道为什么。感谢您提供的任何指导。

1 个答案:

答案 0 :(得分:0)

永远不要说

Selector(("longPress:"))

#selector(longPress)