Swiftui [BUG] NavigationView and List not showing on iPad simulator only
It's actually working just fine. By default, on iPad, the navigationStyle
of a NavigationView
means that you are seeing the detail view with a collapsed master view. Try rotating device or simulator and you will then see your master list. Selecting an item will push that onto the detail view. Or, swipe right from the left edge and your list will appear.
Don't like this behavior? You can set your navigation view's navigationStyle
to StackNavigationViewStyle()
. It will only show a single view on top at any given time.
I can't currently find an option to always show the master view as that is currently how my app is configured using a UISplitViewController
. It is likely a temporary situation.
According to answer of @Procrastin8, I am here to show the example code, you just need to add one line of code .navigationViewStyle(StackNavigationViewStyle()
import SwiftUI
struct LandmarkList: View {
var body: some View {
NavigationView {
List(landmarkData) { landmark in
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
LandmarkRow(landmark: landmark)
}
}
.navigationBarTitle(Text("Landmarks"))
}.navigationViewStyle(StackNavigationViewStyle())
}
}
struct LandmarkList_Previews: PreviewProvider {
static var previews: some View {
ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in
LandmarkList()
.previewDevice(PreviewDevice(rawValue: deviceName))
.previewDisplayName(deviceName)
}
}
}