我正在尝试设置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
我不知道为什么。感谢您提供的任何指导。
答案 0 :(得分:0)
永远不要说
Selector(("longPress:"))
说
#selector(longPress)