'Split View controller occasionally showing detail view on iPhone on iOS 13

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://imgur.com/eWO3RQM



Solution 1:[1]

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.

Solution 2:[2]

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
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 greg
Solution 2 gaurav bhardwaj