UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Three Column Layout Inside TabView

Forums > SwiftUI

Has anyone managed to get this working?

I'm 99% of the way there and have the three column split view working fine, however if one of the tabs is a NavigationView for some reason that tab displays as a two column split view.

In the example below, Tab 3 is a NavigationView and exibits the above problem.

extension UISplitViewController {
    open override func viewDidLoad() {
        preferredDisplayMode = .twoBesideSecondary
        preferredSplitBehavior = .tile
    }
}

struct ContentView: View {

    var body: some View {
        TabView {
            NavigationView {
                Text("ColumnOne").navigationBarTitle("ColumnOne", displayMode: .inline)
                Text("ColumnTwo").navigationBarTitle("ColumnTwo", displayMode: .inline)
                Text("ColumnThree").navigationBarTitle("ColumnThree", displayMode: .inline)
            }
            .tabItem {
                Label("Tab 1", systemImage: "list.dash")
            }
            Text("Tab 2")
            .tabItem {
                Label("Tab 2", systemImage: "list.dash")
            }
            NavigationView {
                Text("Tab 3")
            }
            .tabItem {
                Label("Tab 3", systemImage: "list.dash")
            }
        }
    }
}

2      

If you do not want that then add this modifier to Tab 3 NavigationView and then it will only show one view

.navigationViewStyle(StackNavigationViewStyle())

2      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.