title: Swift UISplitViewController - unable to present master view before detail view (iOS 14, Xcode 12.4)
body: <p>I am having this issue where I am using a UISplitViewController <code>MainSplitVC</code>, and I am unable to present the master view controller over the detail view controller. Basically, when testing this on an iPad, I want the master and detail VC to be visible side by side, but on an iPhone (portrait mode), I want only the master VC. Currently, this works on iPad, but on an iPhone in portrait mode, Swift is showing the detail view controller first, and I have to click the back button in the navigation bar to return to the master view controller.</p>
  <p>I have tried every possible approach that I could think of. For instance, I created a class for the Split View Controller, <code>MainSplitVC</code>, where I subclass <code>UISplitViewController</code> and <code>UISplitViewControllerDelegate</code>. Then, in <code>viewDidLoad()</code>, I set the preferred display mode to <code>oneBesideSecondary</code> (since <code>allVisible</code> was replaced by that according to Xcode). I also include the function <code>collapseSecondary()</code> to always collapse back to the master view controller.</p>
  <pre><code>class MainSplitVC: UISplitViewController, UISplitViewControllerDelegate {
  
      override func viewDidLoad() {
          super.viewDidLoad()
          self.delegate = self
          print(&quot;viewDidLoad called&quot;)
          self.preferredDisplayMode = UISplitViewController.DisplayMode.oneBesideSecondary
      }
  
      func splitViewController(
               _ splitViewController: UISplitViewController,
               collapseSecondary secondaryViewController: UIViewController,
               onto primaryViewController: UIViewController) -&gt; Bool {
          print(&quot;collapseSecondary called&quot;)
          return true
      }
      
  }
  </code></pre>
  <p>I have consulted many other posts regarding this issue, and all the posts indicate that using the <code>collapseSecondary()</code> function and setting <code>preferredDisplayMode</code> to <code>oneBesideSecondary</code> or <code>allVisible</code> should do the job. However, none of this is working. What's more is that the <code>collapseSecondary()</code> function is not even being called, even though I included <code>UISplitViewControllerDelegate</code> in the class header.</p>
  <p>Could anyone clarify if I made any mistakes in the code below? When the app opens, I just want the master view controller to be shown; the detail view controller is simply a blank view controller that changes to another when something in the tableview of the master view controller is clicked.</p>
  <p>The links I used for reference were as follows:</p>
  <ul>
  <li><a href="https://developer.apple.com/forums/thread/106610" rel="nofollow noreferrer">UISplitViewController showing detail view controller first on iPhone, also delegate not calling proper functions</a></li>
  <li><a href="https://stackoverflow.com/questions/25875618/uisplitviewcontroller-in-portrait-on-iphone-shows-detail-vc-instead-of-master">UISplitViewController in portrait on iPhone shows detail VC instead of master</a></li>
  <li><a href="https://stackoverflow.com/questions/29506713/open-uisplitviewcontroller-to-master-view-rather-than-detail#">Open UISplitViewController to Master View rather than Detail</a></li>
  </ul>
  <p>Thanks!</p>
  <p>EDIT 2/3/21: I've resolved the issue. I instead extended <code>SceneDelegate</code> under <code>UISplitViewControllerDelegate</code> and included the following function:</p>
  <pre><code>func splitViewController(_ svc: UISplitViewController, topColumnForCollapsingToProposedTopColumn proposedTopColumn: UISplitViewController.Column) -&gt; UISplitViewController.Column {
      return .primary
  }
  </code></pre>
  <p>The <code>collapseSecondary</code> function didn't work apparently because there is a bug where &quot;Interface Builder doesn’t allow creating a classic style UISplitViewController. (65966010) (FB8107534)&quot;, so I get the error message &quot;Skipping delegate callback, splitViewController:collapseSecondaryViewController:ontoPrimaryViewController:. Unsupported for UISplitViewController style DoubleColumn&quot;.</p>
  <p>Thanks!</p>