I have got my ContentView
, which is a TabView
, with View1
and View2
as tabs:
struct ContentView: View {
@State private var selection: Tab = .View1
enum Tab {
case View1
case View2
}
var body: some View {
TabView(selection: $selection) {
View1()
.tabItem {
Label("View1", systemImage: "")
}
.tag(Tab.View1)
View2()
.tabItem {
Label("View2", systemImage: "")
}
.tag(Tab.View2)
}
}
}
View1
is a NavigationView
with a NavigationLink
to a Subview:
struct View1: View {
var body: some View {
NavigationView {
NavigationLink(destination: Text("Subview1")) {
Text("Hello, View1!")
}
}
}
}
When I'm in the SubView in View1
, change via the tabs to View2
and change back (again, via tab) to View1
, it restores the Subview, which is fine. How can I achieve that by pressing the tab for View1
again, it gets me to the top-level of View1
(i. e. View1
with "Hello, View1"). As of now I have to use the NavigationLink
in the top left corner.