UITabBarController as secondary controller in UISplitViewController is producing 2 navigation bars in compact view

This is a bit of an odd one, but when using UIKit (I've tried it in SwiftUI and the same result doesn't happen), and attempting to place a UITabViewController as the secondary item in a UISplitViewController, an extra UINavigationBar is presented on the secondary view controller, but only when viewed in its compact form. Selected another tab and revisiting that view fixes the problem. Here are some images - a direct screenshot and one from the view debugger:

Here is my code, I've pulled it out of a larger project but it still is reproducible:

import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?

    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = scene as? UIWindowScene else { return }

        let splitViewController = UISplitViewController(style: .doubleColumn)

        let primaryVc = UINavigationController(rootViewController: PrimaryTestUIViewController())
        let tabBar = UITabBarController()
        tabBar.viewControllers = [UINavigationController(rootViewController: SecondaryTestUIViewController()),
                                  UINavigationController(rootViewController: SecondaryTestUIViewController()),
                                  UINavigationController(rootViewController: SecondaryTestUIViewController())]

        let secondaryVC = tabBar

        splitViewController.viewControllers = [primaryVc, secondaryVC]

        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = splitViewController
        self.window = window
        window.makeKeyAndVisible()
    }
}

class PrimaryTestUIViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Primary view"
    }

}

class SecondaryTestUIViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        title = "Secondary view"
    }

}

When using the column based split view controller, it presumes that clients want a navigation controller in each of its non-compact columns and will wrap a view controller in one of not provided. This is primarily so that collapsing (when it moves from multiple to single column) behaves deterministically and automatically.

So what is happening is you're getting a tab bar controller wrapped in a navigation controller with additional navigation controllers inside – and thus double navigation bars.

Realistically this may be a case where you want to create your own custom view controller container instead of using UISplitViewController, as I'm not sure how many of the edge cases you would hit might be resolved.

UITabBarController as secondary controller in UISplitViewController is producing 2 navigation bars in compact view
 
 
Q