Navigation View on iPad?

Hi guys,


I have a small problem with the following code. It works fine if the device is an iPhone (also simulator). If I use an iPad, the screen remains empty (also in the simulator). Where is the error? I can't find one at the moment.


import SwiftUI

struct ContentView: View {
 let l = ["a", "b", "c"]
  
 var body: some View {
  NavigationView {
   List {
    ForEach (l, id: \.self) {l in
     NavigationLink(destination: sv()) {
      Text(l)
     }.navigationBarTitle(Text("List"))
    }
   }
  }
 }
}



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

struct sv: View {
    var body: some View {
        Text("Hello, World!")
    }
}
Answered by Claude31 in 400294022

Thjere is effectively a problem on iPad.

Get a blank screen.

Both tested with XCode 11.2ß2 and 11.3. with simulator 13.2.


But in fact the view is just hidden.

If you drag from the left border to the right, you will see list appear !

Or if you rotate the device.

:or add a .navigationViewStyle


struct ContentView: View {
    let l = ["a", "b", "c"]
   
    var body: some View {
        NavigationView {
            List {
                ForEach (l, id: \.self) {l in
                    NavigationLink(destination: sv()) {
                        Text(l)
                    }.navigationBarTitle(Text("List"))
                }
            }
        }.navigationViewStyle(DoubleColumnNavigationViewStyle())
            .padding()
    }
}


https://stackoverflow.com/questions/57049384/swiftui-navigationview-on-the-ipad-pro

Accepted Answer

Thjere is effectively a problem on iPad.

Get a blank screen.

Both tested with XCode 11.2ß2 and 11.3. with simulator 13.2.


But in fact the view is just hidden.

If you drag from the left border to the right, you will see list appear !

Or if you rotate the device.

:or add a .navigationViewStyle


struct ContentView: View {
    let l = ["a", "b", "c"]
   
    var body: some View {
        NavigationView {
            List {
                ForEach (l, id: \.self) {l in
                    NavigationLink(destination: sv()) {
                        Text(l)
                    }.navigationBarTitle(Text("List"))
                }
            }
        }.navigationViewStyle(DoubleColumnNavigationViewStyle())
            .padding()
    }
}


https://stackoverflow.com/questions/57049384/swiftui-navigationview-on-the-ipad-pro

Hello Claude,


thanks for the confirmation. Let's hope that there will be a fix for this problem in the next version.


Edit: Merci. I see that this is probably the automatic layout adjustment for the iPad, which is playing a trick here.


Have a nice evening

iPad navigation is a bit different from iPhone, I can fix this problem by changing the NavigationView to NavigationStack

import SwiftUI

struct ContentView: View { let l = ["a", "b", "c"]

var body: some View { NavigationStack { List {

Navigation View on iPad?
 
 
Q