MapKit 注释如何添加详细信息披露按钮?

MapKit annotation how to add detail disclosure info button?

我将 annotation 放在地图上,单击图钉后,右侧应该有一个 detail disclosure info button,因此我可以在点击按钮后添加更多代码。但是当我 运行 项目时,点击 pin,没有 info button 出现。任何人都可以提供代码来添加 disclosure info button?

我希望右侧有一个信息按钮:

我的代码:

extension ViewController: MKMapView{


func mapView(mapView: MKMapView!, viewForAnnotation annotation: MKAnnotation!) -> MKAnnotationView! {



  }

创建一个 MKAnnotationView 并向其添加一个按钮。所以:

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        if annotation is MKUserLocation { return nil }

        if let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "") {
            annotationView.annotation = annotation
            return annotationView
        } else {
            let annotationView = MKPinAnnotationView(annotation:annotation, reuseIdentifier:"")
            annotationView.isEnabled = true
            annotationView.canShowCallout = true

            let btn = UIButton(type: .detailDisclosure)
            annotationView.rightCalloutAccessoryView = btn
            return annotationView
        }
    }