UISplitViewController: Deinit DetailView in collap

2019-05-01 03:03发布

I've been struggling on this for a while now, but I wasn't able to find a solution:

I've got an iOS 9 app that supports all device families, uses size classes and is programmed with Swift 2.0. I'm using a UISplitViewController and everything works as I want, except in a collapsed environment (e.g. on an iPhone).

The Master-ViewController is a UITableViewController that triggers a replace segue when a cell is selected. In a collapsed environment this means, that the detailViewcontroller gets pushed onto the screen. The UISplitViewController visually behaves kind of like a UINavigationController. However, when I dismiss the detailViewController with the back button or the swipe gesture it does not get deallocated until the a new replace segue is triggered in the Master-ViewController.

I assume that this is kind of a feature of UISplitViewController, since it was originally designed to show both contents next to each other. Nevertheless, in a collapsed environment I would like my UISplitViewController to behave like a simple UINavigationController, which deallocates the previously pushed detailviewController when popped.

I've been trying to manually change the splitViewController's viewControllers attribute after the detailViewController is popped:

 if let firstVc = self.splitViewController?.viewControllers.first {
        self.splitViewController?.viewControllers = [firstVc]
 }

But that does not help. Simply replacing the detailViewController with an empty "Dummy"-ViewController doesn't work neither, since it automatically animates the transition. Playing around with the UISplitViewControllerDelegate didn't help me neither...

Is there a solution for this (maybe simple? :)), that I'm too blind to see?

0条回答
登录 后发表回答