Column style UISplitViewController not working properly when added to a Tab bar controller

Viewed 346

I tried adding a split view controller with triple column style to a UITabBarController and it shows up in collapsed state. The same code works fine when I use the older style of the split view controller. How do I get the 3-column split view controller to show up correctly on a tab bar controller?

class TabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
//        This works fine ‍♂️
        let splitViewController = SplitViewController()
        splitViewController.viewControllers = [ UINavigationController(rootViewController: PrimaryViewController()) , UINavigationController(rootViewController: SecondaryViewController())]
        
//        let splitViewController = SplitViewController(style: .tripleColumn)
//        splitViewController.setViewController(UINavigationController(rootViewController: PrimaryViewController()), for: .primary)
//        splitViewController.setViewController(UINavigationController(rootViewController: SecondViewController()), for: .secondary)
//        splitViewController.setViewController(UINavigationController(rootViewController: SupplementaryViewController()), for: .supplementary)
//        splitViewController.show(.primary)
//        splitViewController.show(.secondary)
//        splitViewController.show(.supplementary)
        
        splitViewController.title = "First"
        
        let secondViewController = SecondViewController()
        secondViewController.title = "Second"
        
        setViewControllers([
            splitViewController,
            secondViewController
        ], animated: false)
    }
}

here is the link to the project: https://github.com/anirudhbandi96/SplitViewTest

This is how the new three column split view controller looks

enter image description here

This is how the old 2-column split view controller looks

enter image description here

1 Answers

I couldn't even get the 2 column one to work inside a UITabBarController. But, if I just make a new UIViewController, that adds as a childViewController a UISplitViewController, then everything works just fine.

class MyViewController: UIViewController {

    let split = UISplitViewController(style: .doubleColumn)

    override func viewDidLoad() {
        super.viewDidLoad()
        addChild(split)
        view.addSubview(split.view)
        // add in your constraints to fix to same size here
        // -- here --
        split.didMove(toParent: self)
    }
}
 
Related