2

NavigationView nests TabView, I have a List, and push to the next page When the application returns to the background and returns to the active state, the push page automatically pops up.

If TabView nests NavigationView, there will be no problem, but I want NavigationView to nest TabView, is there any way to solve it


struct ContentView: View {
    
    var body: some View {
        
        NavigationView {
            TabView {
                List {
                    ForEach(0..<30) { index in
                        RowView(index: index)
                    }
                }
            }
        }
    }
}



struct RowView: View {
    
    var index: Int
    @State var userViewActive: Int?
    
    var body: some View {
        NavigationLink {
            Text("Hello, world!")
        } label: {
            Text("Hello, world!")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

malhal
  • 26,330
  • 7
  • 115
  • 133
gaohomway
  • 2,132
  • 1
  • 20
  • 37

1 Answers1

2

In a tabview each tab should manage its own view state. Aka

Every tab should have it's own navigation view. If you add this, you will see that your problem is solved.

Bas9990
  • 144
  • 6