通过点击 Mapkit 中的 Annotation 触发 NavigationLink

Trigger NavigationLink through tap on Annotation in Mapkit

我想通过点击 Mapkit 中的注释来触发 NavigationLink。我可以设置一个 bool,某个注释被点击,但我无法通过它调用 SwiftUI 视图。

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

            let identifier = "Annotation"
            var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)

            if annotationView == nil {
                annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier)

                annotationView?.canShowCallout = true

                annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
            } else {
                annotationView?.annotation = annotation
            }

            return annotationView
        }

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
            let selectedAssistance = self.parent.assistances.first {
                    [=10=].location.location?.coordinate == view.annotation?.coordinate
            }

            guard selectedAssistance != nil else {
                return
            }

            self.parent.selectedAssistance = selectedAssistance?.serverId ?? ""
            self.parent.presentSheet = true
        }

我做到了,通过在 ZStack 中调用我自己的 MapView,并在它后面放置一个 NavLink,它在 Binding 上处于活动状态