Search code examples
swiftswiftuinavigationview

NavigationView SwiftUI shows split view in iPad


With NavigationView being the root of UIHostingController , the below code shows split view for iPad.

struct ContentView: View {
    var body: some View {
        
        NavigationView {
            Text("Hello")
                .navigationBarTitle("Home")
        }
    }
}

With the above code it shows split view on iPad. How can I still use the NavigationView and get rid of split view for iPad , as I am looking to have a List and on tap of which it should push another view?

enter image description here enter image description here


Solution

  • Use stack navigation view style explicitly (by default it is platform-dependent)

    NavigationView {
       Text("Hello")
           .navigationBarTitle("Home")
    }
    .navigationViewStyle(StackNavigationViewStyle())