SwiftUI Duplicate NavBars with Form Picker

Viewed 130

I am getting a second back button when I do a form picker.

First view comes from another view. (so that makes it the second view?)

enter image description here

After I choose the picker I get this.

enter image description here

There is nothing fancy in the code.

How can I avoid this?

  NavigationView {
         
        Form {
              
                Text("text")
                
                Picker(selection:  .constant(1) , label:  Text("Picker") ) {
                     Text("1").tag(1) 
                     Text("2").tag(2) 
                }
            
            Spacer()
                
             
        }
         
    }
    .navigationBarTitle("Settings")

Thank you.

1 Answers

It looks like parent view already has NavigationView, so, by concept there should be only one navigation view in view hierarchy, you should just remove second one

  // NavigationView { // << remove this one
         
        Form {
              
                Text("text")
                
                Picker(selection:  .constant(1) , label:  Text("Picker") ) {
                     Text("1").tag(1) 
                     Text("2").tag(2) 
                }
            
            Spacer()
                
             
        }
        .navigationBarTitle("Settings")    // << specify on Form !!
Related