Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 注释上的按钮未出现_Swift_Xcode_Swift3_Mapkit_Mapkitannotation - Fatal编程技术网

Swift 注释上的按钮未出现

Swift 注释上的按钮未出现,swift,xcode,swift3,mapkit,mapkitannotation,Swift,Xcode,Swift3,Mapkit,Mapkitannotation,我的应用程序有问题。事实上,当我在一个单独的应用程序中运行我的代码时,它正在工作。xCode没有向我显示任何错误,一切正常,但我在MapKit上的注释中看不到详细信息按钮。xCode有更深层次的问题吗 这是我的代码: func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let identifier = "Education" if

我的应用程序有问题。事实上,当我在一个单独的应用程序中运行我的代码时,它正在工作。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
}

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

mapView.delgate=self

是您需要添加的代码