How to avoid to go to the NavigationLink target when using an iPad?

Viewed 54

if I have an app with some master/detail view with the following code:

import SwiftUI

struct ContentView: View {
    var body: some View {
        NavigationView {
            NavigationLink(destination: DetailView()) {
                Text("Go to details")
            }
        }
    }
}

struct DetailView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
    }
}

The problem here is, that I want that also on the iPad the user first need to see the master page and not directly the detail view. But by default if you start the app it looks like this:

enter image description here

How to keep the master view open when the app starts on the iPad?

1 Answers

You could check the device type, if it's .pad then you show the master page:

if UIDevice.current.userInterfaceIdiom == .pad{
//Show master page
}
Related