When user taps on mapview annotation rightCalloutAccessoryView disclosure button, I want to navigate to another view
struct ProfileMapView: View {
var body: some View {
NavigationView {
ZStack {
VStack (alignment: .leading){
MapView(locationPins: $locationPins)
.ignoresSafeArea()
}
}
}
}
struct MapView: UIViewRepresentable {
// some code
class MapViewDelegate: MKMapView, MKMapViewDelegate {
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
//MARK:- delegate method
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {
if control == view.rightCalloutAccessoryView {
mapView.deselectAnnotation(view.annotation, animated: true)
for detail in self.myAnnotations {
locationId = detail.locationId
providerType = detail.providerType
NavigationStack {
VStack {
Text("test")
NavigationLink(
destination: ProfileDetailsView(locationId: $locationId, providerType: $providerType),
isActive: $isNavigationActive
) {
EmptyView()
}
}
}
break
}
}
}
}
}
}
}
When I run it does not navigate to ProfileDetailsView. Instead debugger window shows a message: "Accessing State's value outside of being installed on a View. This will result in a constant Binding of the initial value and will not update." Also on the NavigationLink line, I get a warning "Result of 'NavigationLink<Label, Destination>' initializer is unused" How to navigate to another view from calloutAccessoryControlTapped method?
NavigationLink
to work it needs aNavigationStack
.