I'm using MapKit in Xcode 11.1 with SwiftUI to show a map with annotations. The annotations have a callout which shows the title, and a button on the rightCalloutAccessoryView. I want to be able to navigate to another view when the user clicks the rightCalloutAccessoryView button.
A NavigationLink within the calloutAccessoryControlTapped function isn't working. How should this be done in SwiftUI? Any help is much appreciated!
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "AnnotationView")
if annotationView == nil {
annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "AnnotationView")
}
let whiteImage = UIImage(named: "white")
annotationView!.image = whiteImage
annotationView?.isEnabled = true
annotationView?.canShowCallout = true
annotationView?.centerOffset = CGPoint(x: 0, y: -23)
let button = UIButton(type: .detailDisclosure)
annotationView?.rightCalloutAccessoryView = button
return annotationView
}
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
@State var tapped = true
//ERROR: Property wrappers are not yet supported on local properties
NavigationLink(destination: DetailView(), isActive: $tapped) {EmptyView()}
//ERROR: Use of unrecognized identifier '$tapped'
}