Mapbox - calloutAccessoryControllerTapped

Mapbox - calloutAccessoryControllerTapped

我的 calloutAccessoryControllerTapped 有问题。此时我的标注中有两个按钮 - 每个按钮都会跳转到我的地图视图上的模式弹出窗口。在我的 segue 工作的那一刻,但两个按钮都转到同一个弹出窗口。我需要能够区分按钮及其 segue。

这可能吗?我用谷歌搜索了这个问题,很多答案似乎都建议使用下面的这行代码

if (control == view.leftCalloutAccessoryView) {

但是,这会出现错误“'UIView' 类型的值没有成员 'leftCalloutAccessoryView'”。如果有人能帮助我解决这个问题,我将不胜感激,如果我没有,我将深表歉意把问题说清楚了,我已经尽力了。

下面是我的代码:

func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {

    return true


}


func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {


    self.performSegue(withIdentifier: "Show", sender: view)

}

func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {

    guard let skateAnnotation = annotation as? SkateAnnotation else { return nil }

    if skateAnnotation.canEdit {
        return UIButton(type: .detailDisclosure)
    }

    return nil


}

func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {

    return UIButton(type: .contactAdd)


}



 func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {

    return nil

}


}

像这样的简单操作(根据需要更改代码)可以区分左右标注附件控件。

func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
    let button = UIButton(type: .detailDisclosure)
    button.tag = 100
    return button
}

func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
    let button = UIButton(type: .detailDisclosure)
    button.tag = 101
    return button
}

func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
    // Hide the callout view.
    mapView.deselectAnnotation(annotation, animated: false)

    if control.tag == 100 {
        print("left")
    } else if control.tag == 101 {
        print("right")
    }
}