I use the Apple SwiftUI tutorial code. Then I set the previewDevice to iPad Pro (12.9-inch). But the preview has something wrong. Does anyone know where the problem is?
-
2Have you tried sliding out the "drawer" on the left side (swipe in from left)? In portrait mode an iPad auto hides the master view in a master-detail UI. – A.C. Wright Jul 16 '19 at 02:53
-
wow~ thank you for your reminder. Btw, can I set the navigation view like the iphone? – Jerry Lee Jul 16 '19 at 03:07
-
1I'm not sure. I have not figured out a way to do that. But I ran into your issue while experimenting and thought I could help with that! – A.C. Wright Jul 16 '19 at 03:08
-
1As of Beta 4 there is a new property on NavigationView that allows you to lay out the master-detail in two columns: `.navigationViewStyle(.doubleColumn)` – A.C. Wright Jul 17 '19 at 13:32
-
Look here -> https://stackoverflow.com/a/66665464/7278926 – iGhost Mar 17 '21 at 00:42
8 Answers
You can override the default splitView used on iPad, by having the NavigationView display the same stacked view you see on iPhone, by setting
.navigationViewStyle(StackNavigationViewStyle())
Quite helpful during development and debugging, and when you have not developed the detailedView() yet.

- 1,121
- 1
- 7
- 6
-
I want to see the detail view I'm working on in my preview, so this is exactly what I needed to add to my `PreviewProvider`. Thanks! – Tony the Tech Dec 27 '20 at 19:26
-
when I use this on iOS 15, navigation bar becomes invisible in certain cases, without this modifier it doesn't, but then I have the wrong navigation style on iPad (default instead of stack - which I want to use). – tadija Oct 19 '21 at 21:16
-
1
In my case what make the difference was using StackNavigationViewStyle
and no padding were needed.
NavigationView {
...
}
.navigationViewStyle(StackNavigationViewStyle())

- 1,307
- 11
- 6
Slide the drawer from the left side of the screen.
If you would to remove the drawer and have it constant, you can do the following (note the padding is what makes the drawer constant):
.navigationViewStyle(DefaultNavigationViewStyle())
.padding(0)
or
.navigationViewStyle(DoubleColumnNavigationViewStyle())
.padding(0)
Note: This does not currently work perfectly with all iPad views. For example on the iPad 9.7in, the above padding(0) would make the portrait view have the list, but the landscape view have the slideout. This would also not work correctly on the iPad 12.9in. If you don't have the padding included, it works in landscape on the 9.7in, but not in portrait.

- 404
- 3
- 8
It looks like the master view (the one on the left) is hidden on iPads running iOS 13 by design. The master view is there, you can pull it out from the left edge of the screen.
Unfortunately, there is currently no API to opt-out of this behavior other than applying a non-zero padding for the leading
edge:
var body: some View {
GeometryReader { geometry in
NavigationView {
self.content
}.padding(.leading, self.leadingPadding(geometry))
}
}
private func leadingPadding(_ geometry: GeometryProxy) -> CGFloat {
if UIDevice.current.userInterfaceIdiom == .pad {
// A hack for correct display of the SplitView in SwiftUI on iPad
return geometry.size.width < geometry.size.height ? 0.5 : -0.5
}
return 0
}

- 10,615
- 6
- 44
- 48
-
This looked really promising, but doesn't work for Plus-sized iPhones in landscape. (The master view still needs to be dragged in manually) – Matthew Mar 22 '20 at 15:35
You have embedded your body in NavigationView.In iPad,you have to slide the drawer from left side to view your content view.
Remove NavigationView and observe the behaviour
To override default behaviour, use below code
NavigationView {
...
}
.navigationViewStyle(DoubleColumnNavigationViewStyle())
.padding()

- 89
- 1
- 4
-
I notice that, in the standard view style, the detail view in the OP's mentioned tutorial runs underneath the list view, making it useless. Using double-column style restricts the detail view to the exposed screen area, which is what the view design is expecting. – brotskydotcom Dec 27 '19 at 19:21
Correct Solution!
All the answers here were unhelpful as they were missing a vital view to be shown before a selection has been made in the NavigationView. This is necessary on iPad if both views are to be visible at the start!
To use .columns
in NavigationView
, we should provide a default Detail view that is to be shown, when nothing has been selected, i.e. WordView("")
.
struct ContentView: View {
@State private var words: [String] = []
@State private var selected: String?
@FocusState private var isFocused: Bool
var body: some View {
NavigationView {
List(selection: $selected) {
ForEach(words) { word in
NavigationLink(tag: word, selection: $selected) {
WordView(word)
} label: {
Text(word)
}
}
.task {
isFocused = true
}
}
.navigationTitle("Words")
.navigationViewStyle(.columns)
// Detail view shown when nothing has been selected
WordView("")
}
}
}

- 17,970
- 5
- 66
- 62
Using the code provided by nalexn I came up with this as the solution.
As commented by matthew in the same post iPhones in landscape mode will still cause the drawer to be hidden thus, using StackNavigationViewStyle()
is more suitable for iPhone whilst for iPad it will use the DoubleColumnNavigationViewStyle()
var body: some View {
GeometryReader{ geo in
if (UIDevice.current.userInterfaceIdiom == .pad){
NavigationView{
self.makeContents()
}.navigationViewStyle(DoubleColumnNavigationViewStyle())
.padding(.leading, geo.size.width < geo.size.height ? 0.25 : 0)
}else{
NavigationView{
self.makeContents()
}.navigationViewStyle(StackNavigationViewStyle())
}
}
}
Hope this helps anyone that comes to this post after me :D

- 289
- 2
- 9
Use this
NavigationView {}.navigationViewStyle(.stack)

- 1
- 2
-
This is a duplicate answer and does not provide any new information. The top voted answer by Sondergaard has this method, and Gurjinder Singh has updated the method for the most recent OS. – Ben A. Aug 29 '23 at 00:05
-
I mentioned this because in their one-line code, I was not able to understand do I need to write this line inside or outside the block of NavigationView. So, clarifying that thing I wrote the above answer.... – Kinjal Panchal Aug 29 '23 at 13:14