Reputation: 363
I have a NavigationView with three NavigationLinks, on portrait iPhone, it works as expected where one taps a link, a new view is presented with a Back button. However on an iPad in landscape (which this app is designed for only), iOS forces a slideout menu from the left side instead of showing the three links on the view.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
HStack {
NavigationLink(destination: ContentView()) {
Text("Item 1")
}
NavigationLink(destination: ContentViewC()) {
Text("Item 2")
}
NavigationLink(destination: ContentViewB()) {
Text("Item 3")
}
}
}
}
}
Any suggestions for overriding this behavior?
Upvotes: 0
Views: 42
Reputation: 52387
You can solve this issue by adding this
.navigationViewStyle(StackNavigationViewStyle())
to your NavigationView
NavigationView {
...
}.navigationViewStyle(StackNavigationViewStyle())
This will force it to render a standard stack (like you see on the phone) rather than defaulting to the split view layout.
Upvotes: 3