0

我可以使用以下代码在我的地图注释中显示一个披露图标。

  annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier)
            annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)

当您按下披露图标时,它会闪烁,但不会发生其他任何事情。我尝试在其上放置一个按钮处理程序,但它不是一个按钮,所以编译器说不。我是否必须创建一个完整的手势识别器才能让它做任何事情,或者我如何在指示器上按下以显示有关位置的信息?

4

2 回答 2

1

你需要这个委托方法

func mapView(_ mapView: MKMapView, 
   annotationView view: MKAnnotationView, 
   calloutAccessoryControlTapped control: UIControl)

self.mapView.delegate = self
于 2018-11-14T20:07:05.770 回答
-1

尝试这个

   let btn = UIButton(type: .detailDisclosure)
   btn.addTarget(self, action: #selector(btnDisclosureAction(_:)), for: .touchUpInside)
   annotationView.rightCalloutAccessoryView = btn

    @objc func btnDisclosureAction(_ sender: UIButton) {
        // you action
    }
于 2018-11-14T19:55:32.663 回答