UISplitViewController and iOS14


Rick Aurbach
 

I have a storyboard-based app based on a split-view. I have edited the split view as shown in the attached screenshot.



My goal is to have a single storyboard that will handle both iPhone and iPad targets, running pre-iOS14 and iOS14+ apps. 

This is pretty much working (using the code shown below). But, on iPhone, I want the .primary column to be initially displayed on application launch. Pre-14, I guaranteed this by implementing splitViewController(_:collapseSecondary:onto:). In iOS14, this isn't getting called because the style is not .unspecified. I tried implementing splitViewController(_:topColumnFor:), but it is never called.

Any ideas on how to force the .primary column to be displayed on application launch?

class SplitViewController : UISplitViewControllerUISplitViewControllerDelegate {

override func viewDidLoad() {

super.viewDidLoad()

 

self.delegate = self

 

if #available(iOS 14.0, *) {

if UIDevice.current.userInterfaceIdiom == .phone {

show(.primary)

}

else {

if UIDevice.current.userInterfaceIdiom == .pad {

preferredDisplayMode = .allVisible

}

}

}

// MARK: - Split view

 

func splitViewController(_ svc: UISplitViewController, willChangeTo displayMode: UISplitViewController.DisplayMode) {

if #available(iOS 14.0, *) {

else {

if displayMode != .allVisibleself.viewControllers.count > 1 {

if let detailNavController = self.viewControllers[1asUINavigationController {

detailNavController.topViewController!.navigationItem.leftBarButtonItem = self.displayModeButtonItem

}

}

}

}

 

@available(iOS 14.0, *)

func splitViewConntroller(_ svc: UISplitViewController, topColumnFor CollapsingToProposedTopColoum: UISplitViewController.Column) -> UISplitViewController.Column {

return .primary

}

 

 

func splitViewController(_ splitViewController: UISplitViewController,

                         collapseSecondary secondaryViewController:UIViewController,

                         onto primaryViewController:UIViewController) -> Bool {

return true

}

}