2

I have noticed that TabView has another behavior than UITabBarController, the view stack is cleared each time the user moves from one tab to another.

I have created a small sample to illustrate my case:

struct ContentView: View {
    @State private var selection = 0

    var body: some View {
        TabView(selection: $selection) {
            NavView(id: "A").tabItem { Text("Alpha") }.tag(0)
            NavView(id: "B").tabItem { Text("Beta") }.tag(1)
        }
    }
}

struct NavView: View {
    var id: String

    var body: some View {
        NavigationView {
            List {
                NavigationLink(destination: Text("Detail \(id)")) { Text(id) }
            }
        }
    }
}

The detail view is gone since the NavView is recreated after a visit to the other tab.

Question: Is there a way to recreate the old behavior, that a presented detail view is still present after a visit on another tab?

JKvr
  • 650
  • 7
  • 15
  • Possible duplicate of [TabView resets navigation stack when switching tabs](https://stackoverflow.com/questions/57772137/tabview-resets-navigation-stack-when-switching-tabs) – John M. Oct 16 '19 at 16:18
  • See https://stackoverflow.com/questions/57772137/tabview-resets-navigation-stack-when-switching-tabs/57979601#57979601. There's no good SwiftUI solution yet, this question-asker wrapped a UITabView. – John M. Oct 16 '19 at 16:19

0 Answers0