0

我的应用程序有问题。事实上,当我在一个单独的应用程序中运行我的代码时,它正在工作。xCode 没有向我显示任何错误,一切正常,但我在 MapKit 的注释中看不到详细信息按钮。xCode 中是否存在更深层次的问题?

那是我的代码:

    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    let identifier = "Education"

    if annotation is Education {
        var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

        if annotationView == nil {
            annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            annotationView!.canShowCallout = true

            let btn = UIButton(type: .detailDisclosure)
            annotationView!.rightCalloutAccessoryView = btn
        } else {

            annotationView!.annotation = annotation
        }

        return annotationView
    }

    return nil
}

在我的应用程序上看起来像这样 - 注释右侧没有详细信息按钮。

4

1 回答 1

0

您必须为您的 mapView 设置委托。我通常在 mapView 所在的 ViewController 的 viewDidLoad 中执行此操作。

mapView.delgate = self

是您需要添加的代码。

于 2017-05-16T03:39:37.400 回答