UISplitViewController: Deinit DetailView in collapsed mode

青春壹個敷衍的年華 提交于 2019-12-22 05:58:49

问题


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?

来源:https://stackoverflow.com/questions/33238786/uisplitviewcontroller-deinit-detailview-in-collapsed-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!