title: iPad crash: Unexpected view controller change in Supplementary column
body: <p>I'm receiving repetitive crash logs related to the UISplitController supplementary column.</p>
  <blockquote>
  <p>Fatal Exception: NSInternalInconsistencyException</p>
  <p>Unexpected view controller change in Supplementary column for expanding &lt;xxxx.CustomSplitViewController: 0x15bb0bf40&gt;</p>
  </blockquote>
  <p>I can't reproduce it and the logs have no reference at all to any of my code - I'm wondering if it can be somehow related to orientation changes.</p>
  <p>Any help would be very appreciated.</p>
  <p>Here is part of the crash log:</p>
  <pre><code>Fatal Exception: NSInternalInconsistencyException
  0  CoreFoundation                 0x9904c __exceptionPreprocess
  1  libobjc.A.dylib                0x15f54 objc_exception_throw
  2  Foundation                     0x1306cc _userInfoForFileAndLine
  3  UIKitCore                      0x991928 -[UISplitViewControllerPanelImpl panelController:separateSupplementaryViewControllerFromPrimaryViewController:]
  4  UIKitCore                      0x96699c __54-[UIPanelController _expandWithTransitionCoordinator:]_block_invoke_4
  5  UIKitCore                      0xb0d78 +[UIPanelController _withDisabledAppearanceTransitions:forVisibleDescendantsOf:perform:]
  6  UIKitCore                      0xb0940 -[UIPanelController _withDisabledAppearanceTransitionsPerform:]
  7  UIKitCore                      0x9668c0 __54-[UIPanelController _expandWithTransitionCoordinator:]_block_invoke_3
  8  UIKitCore                      0x1c6a08 +[UIViewController _performWithoutDeferringTransitionsAllowingAnimation:actions:]
  9  UIKitCore                      0x966814 __54-[UIPanelController _expandWithTransitionCoordinator:]_block_invoke_2
  10 UIKitCore                      0x174268 +[UIView(Animation) performWithoutAnimation:]
  11 UIKitCore                      0x966760 __54-[UIPanelController _expandWithTransitionCoordinator:]_block_invoke
  12 UIKitCore                      0x26fc28 -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:]
  13 UIKitCore                      0x529ae8 -[_UIViewControllerTransitionContext __runAlongsideAnimations]
  14 UIKitCore                      0x4f49ac -[_UIWindowAnimationController animateTransition:]
  15 UIKitCore                      0xb70dc -[UIWindow _adjustSizeClassesAndResizeWindowToFrame:]
  16 UIKitCore                      0x23e408 -[UIWindow _resizeWindowFrameToSceneBoundsIfNecessary]
  17 UIKitCore                      0x461bd8 -[UIWindow _sceneBoundsDidChange]
  18 UIKitCore                      0x5802e8 -[_UIScenefbsSceneBasedMetricsCalculator _updateMetricsOnWindows:animated:]
  19 UIKitCore                      0x2b9fcc -[UIWindowScene _computeMetricsForWindows:animated:]
  20 UIKitCore                      0x2e98a8 -[UIWindowScene _computeMetrics:]
  21 UIKitCore                      0x270350 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:actions:completion:]
  22 UIKitCore                      0x1b2340 _UISceneSettingsDiffActionPerformChangesWithTransitionContext
  </code></pre>
  <p>As for code, I set the controller on supplementary column once on viewDidLoad, and after that from user interaction (selecting a collection view cell on the primary column):</p>
  <pre><code>func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
      ...
      let vc = UINavigationController(rootViewController: storyboard.instantiateViewController(withIdentifier: controllerID.rawValue))
      splitViewController?.setViewController(vc, for: .supplementary)
      ...
  }
  </code></pre>
  <p>And for rotation, on viewWillTransition I'm changing the display mode and split behaviour:</p>
  <pre><code>open override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
      super.viewWillTransition(to: size, with: coordinator)
      setDisplayMode()
  }
  
  func setDisplayMode() {
      let orientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation
      if orientation?.isPortrait == true {
          splitViewController?.preferredDisplayMode = .oneBesideSecondary
          splitViewController?.preferredSplitBehavior = .overlay
      } else {
          splitViewController?.preferredDisplayMode = .twoBesideSecondary
          splitViewController?.preferredSplitBehavior = .tile
      }
  }
  </code></pre>
  <p>Update: The crash seems to be related to setting preferredDisplayMode and preferredSplitBehavior on rotation, but I still can't reproduce it. And I need the different settings depending on orientation.</p>