4

We have a universal app with Split view controllers which are embedded within the different tabs. We're observing that on iOS 13 on iPhone, and while switching tabs, the detail view is showed instead of the master view occasionally. We have not been able to single out the pattern and this just happens randomly, but frequently.

I have already referred to UISplitViewController in portrait on iPhone shows detail VC instead of master and Open UISplitViewController to Master View rather than Detail and we're implementing the delegate for SplitViewController. This delegate also gets called.


class AppSplitViewController: UISplitViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        self.delegate = self
        self.preferredDisplayMode = .allVisible
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

// MARK: - UISplitViewControllerDelegate Methods
extension AppSplitViewController: UISplitViewControllerDelegate {
    func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController: UIViewController, onto primaryViewController: UIViewController) -> Bool {
        return true
    }
}

I am not sure if other people have observed this on iOS 13 as well or not, but I am not sure why iOS would present detail view occasionally even though we have the proper delegate implementation. Please note that we have not been able to reproduce this on iOS 12. Here is view stack https://i.stack.imgur.com/YrcKL.jpg

Abhinav Singh
  • 243
  • 1
  • 13
  • I'm still seeing this happen even on iOS 15. Also unable to reproduce it reliably. – TylerJames Oct 05 '21 at 16:19
  • @TylerJames So when app the is going to background, I ended up setting the flag in app delegate and then did this // If it is only iPhone and navigating from the background, then the delegate method doesn't gets called, we have to manually pop the controller if userInterfaceIdiom != .pad, let isComingFromBackground = (UIApplication.shared.delegate as? AppDelegate)?.isComingFromBackground, isComingFromBackground, let nav = self.viewControllers.first as? UINavigationController { nav.popToRootViewController(animated:false) } – Abhinav Singh Feb 16 '22 at 23:45

2 Answers2

0

Set the UISplitViewController delegate again in awakeFromNib. There appears to be some order of operations issue, from iOS 13 to at least 13.3. I had the exact same issue, and implemented this tip as a result of another answer, which seems to be working.

greg
  • 4,843
  • 32
  • 47
0

The below newly introduced method could be helpful if you are using iOS 14 or above

func splitViewController(_ svc: UISplitViewController, topColumnForCollapsingToProposedTopColumn proposedTopColumn: UISplitViewController.Column) -> UISplitViewController.Column {
    return .primary
}