0

The following NavigationView contains a primary master and secondary detail view:

struct ContentView: View {
    var body: some View {
        NavigationView {
            Text("Primary View")
                .navigationTitle("Primary")
            Text("Secondary View")
                .navigationTitle("Secondary")
        }
    }
}

When used with an iPad in any orientation everything works as expected. The primary view is shown in the sidebar and the secondary view is shown in the main content area:

iPad in landscape

When used on an iPhone the primary view is displayed and there seems to be no way to access the secondary view:

iPhone in portrait

What is the correct way to set up a master/detail NavigationView on the iPhone?

sbooth
  • 16,646
  • 2
  • 55
  • 81
  • I do not believe that you can get the same result on iPhone! At last this is Apple API and they decide if you can use that option! but I think in landscape mode in iPhone is possible, but it could be deferent in iPhone to iPhone! like should be possible in all Pro Max´s but not sure about SE or other small iPhones! – ios coder Sep 19 '21 at 23:12
  • I don't necessarily mean duplicate the iPad behavior, but just have both views be visible/usable? – sbooth Sep 19 '21 at 23:34
  • What you mean or not mean has no role to play in what is available for us. – ios coder Sep 20 '21 at 00:26

1 Answers1

0

If all you want to show is the secondary view when horizontal size is compact, why not just show it? The master view is there to provide selections for the user for navigating.

Otherwise, you don't have a NavigationLink and that is what will push the secondary view when horizontal size is compact.

NavigationView {
    VStack {
        NavigationLink("Choice 1", Text("Choice 1"))
        ...
    }
    Text("Secondary View").navigationTitle("Secondary")