I have this simple code:
import SwiftUI
struct ExampleView: View {
@State private var selectedTab: String = "tab1"
var body: some View {
VStack {
Picker("Mode", selection: $selectedTab) {
Text("tab1").tag("tab1")
Text("tab2").tag("tab2")
Text("tab3").tag("tab3")
}
.pickerStyle(.segmented)
.padding([.horizontal, .top])
Form {
switch selectedTab {
case "tab1":
TabOneView()
case "tab2":
TabTwoView()
case "tab3":
TabThreeView()
default:
TabOneView()
}
}
}
.navigationTitle("Title")
.navigationBarTitleDisplayMode(.inline)
}
}
When I try this in the preview it works correctly, but when I use it in the app, where this View is called with a NavigationLink from another View the picker seems freeze: pressing another option does not change the value and so also the view does not change (also visually, the default option remains selected).
The parent View:
struct ParentView: View {
var body: some View {
Form {
// some other code
Section(header: Text("SUBVIEWS")) {
NavigationLink {
ExampleView()
} label: {
Text("Example")
}
NavigationLink {
Example2View()
} label: {
Text("Example2")
}
}
}
.navigationTitle("ParentView")
.navigationBarTitleDisplayMode(.inline)
}
}
I also tried to print the values with in method .onChange on the variable selectedTab, but it does not print anything (synonym that the value is not changed).

Viewis called with aNavigationLinkfrom anotherView".