Search code examples
swiftuiuisplitviewcontrollernavigationview

SwiftUI NavigationView Secondary not showing


Using Xcode 12.4 running on the simulator using iOS 14.4

Running the following code:

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

The following is rendered in Landscape:

enter image description here

I would was expecting to see "Secondary" with a Back Button in the top left corner to navigate back to the "some View". All of the YouTube videos I have seen behave in the manor I have just described.

Any clue as to why this isn't behaving as expected?


Solution

  • This is expected behavior on devices with a "compact width" size class.

    On devices that report "regular width", you will see the split NavigationView.

    You can see the table of device and size classes at: https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/