I have a two column NavigationSplitView with a linked NavigationSplitViewVisibility variable. On the iPad everything works as expected. Tapping on the “Go to Detail View” in the sidebar will go to the Detail view. However on the iPhone nothing happens.
Any ideas how to resolve this.
Thanks
Here is the code:
struct ContentView: View {
@State var visibility:NavigationSplitViewVisibility = .all
var body: some View {
NavigationSplitView( columnVisibility:$visibility) {
Text("Go to Detail View" )
.onTapGesture {
visibility = .detailOnly
}
} detail: {
Text( "Show Sidebar")
.onTapGesture {
visibility = .all
}
}
}
}
NavigationSplitView
doesn't show multiple columns in an iPhone, apart from larger ones (e.g iPhone 14 Pro Max) in landscape.From Apple's documentation
If you use
NavigationLink
s in thesidebar
, theNavigationSplitView
on an iPhone works just like a regularNavigationStack
. On larger devices the contents ofdetail
is only displayed when no link is selected.In the example below, tapping the "Hide sidebar" button would do nothing, so I've added a
horizontalSizeClass
Environment
variable, which allows the button to be hidden on smaller devices.