Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.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
Ios 如何将按钮添加到MapKit详图索引Swift 3_Ios_Swift_Firebase_Mapkit - Fatal编程技术网

Ios 如何将按钮添加到MapKit详图索引Swift 3

Ios 如何将按钮添加到MapKit详图索引Swift 3,ios,swift,firebase,mapkit,Ios,Swift,Firebase,Mapkit,我正在尝试向详图索引添加一个按钮,以便可以过渡到另一个视图控制器。然而,标注不会显示附件视图,我不确定原因。我从firebase中获取一些数据并将其输入到适当的数组中,然后在调用时发布注释。我不知道为什么按钮没有显示出来 此代码发生在ViewDidLoad()中{…} 我也使用了这个函数 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { // If

我正在尝试向详图索引添加一个按钮,以便可以过渡到另一个视图控制器。然而,标注不会显示附件视图,我不确定原因。我从firebase中获取一些数据并将其输入到适当的数组中,然后在调用时发布注释。我不知道为什么按钮没有显示出来

此代码发生在ViewDidLoad()中{…}

我也使用了这个函数

 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    // If annotation is not of type RestaurantAnnotation (MKUserLocation types for instance), return nil


    var annotationView = self.Map.dequeueReusableAnnotationView(withIdentifier: "Pin")

    if annotationView == nil{
        annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "Pin")
        annotationView?.canShowCallout = true
        annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
    }else{
        annotationView?.annotation = annotation
    }



    return annotationView
}
编辑:请求使用imgage


你的流量控制很奇怪

为什么只在
如果annotationView==nil
时添加CalloutAccessoryView

请尝试以下代码:

if annotationView == nil{
    annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "Pin")  
}else{
    annotationView?.annotation = annotation
}
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
我猜
self.Map.dequeueReusableAnnotationView(带标识符:“Pin”)
可能会返回nil,因为我没有看到您的代码

返回值

具有指定标识符的注释视图,如果重用队列中不存在此类对象,则为nil


但是当它无你也需要添加附件

我犯了一个非常愚蠢的错误。。。我忘了放置
Map.delegate.self
,因此该函数从未被实际调用是有意义的。按钮现在显示感谢大家的帮助

当我使用此代码时,它没有显示按钮。只有带标题但没有按钮的详图索引可以捕获详图索引附件的图像。。。它是否在Callout附件的右侧留下空白?我添加了一张图片。它没有在那里留下任何空间。
if annotationView == nil{
    annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "Pin")  
}else{
    annotationView?.annotation = annotation
}
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)