Reputation: 655
Weird problem.
I have a view called SecondView
which has a NavigationLink
like so:
struct SecondView: View {
var body: some View {
NavigationStack {
List {
Section {
EmptyView()
}
//PowerUp Section
Section {
VStack {
NavigationLink (destination: Powerup()) {
Text("2")
}
.isDetailLink(false)
}
}
}
}
}
}
This view is embedded in a modal view.
The NavigationLink
works fine when I preview SecondView
on Xcode but doesn't when I preview the modal sheet.
Doesn't work on an actual device or simulator too.
Looks like a hierarchy problem or something like this.
Can someone tell me where I'm wrong?
Thanks.
Upvotes: 1
Views: 863
Reputation: 30582
Since the old NavigationLink(destination:)
has some severe limitations, you are supposed to use NavigationLink(value:)
and .navigationDestination(for:)
when using the new NavigationStack
, e.g.
NavigationStack {
List(parks) { park in
NavigationLink(park.name, value: park)
}
.navigationDestination(for: Park.self) { park in
ParkDetails(park: park)
}
}
Upvotes: 2
Reputation: 655
Auto-solved the problem.
I was embedding SecondView
in the modal in the wrong way.
The view should be wrapped in a NavigationView
and a NavigationStack
first.
Maybe it's helpful to someone else.
Upvotes: 1