0
votes

I'm using SwiftUI to set up a 3-column navigation view with a sidebar for iPadOS and a TabView for iOS.

However, I'm unable to get the sidebar functionality with the sidebar toggle icon in the 3 column view. As soon as I switch to 2 column view, I get the sidebar toggle icon automatically. But it disappears in 3 column.

Here's the missing icon in 3 column view:

Missing Icon Image

And here's the toggle icon with the same code when I switch to 2 column view:

2 Column View Image

Here's the code:

struct MainView: View {
    var body: some View {
        if UIDevice.current.userInterfaceIdiom == .phone {
            TabBarView()
        } else {
            NavigationView {
                Sidebar()
                Text("1")
                Text("2")
            }
        }
    }
}

How do I get the sidebar toggle icon to appear in the 3 column view? Note that the toggle icon that is provided by SwiftUI automatically appears on sidebar and primary view on being collapsed and expanded, which is the functionality I'm looking for (example: In contacts or mail app on the iPad).

SwiftUI doesn’t expose any option for the multi-column view, unfortunately. If you check the documentation for UISplitViewController, you’ll see there are many options: developer.apple.com/documentation/uikit/uisplitviewcontroller. SwiftUI seems to be using the “two displacing content” layout, which won’t show the sidebar toggle. If you want a different layout, you need to use UISplitViewController directly instead of SwiftUI. - Adam