UISplitViewController: Deinit DetailView in collapsed mode
Asked Answered
L

0

6

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?

Loincloth answered 20/10, 2015 at 14:0 Comment(4)
If you've solved this problem, please add the answer. This will help other users.Externalize
@Externalize unfortunately I didn't solve it yet. Had to built a workaroundLoincloth
@Loincloth can you give a brief explanation of your workaround?Nahshunn
@SAHM, the workaround was basically to handle this situation manually on the detailViewController, meaning that I had to stop all active tasks/calculation, etc. and only to run them when the screen was actually visible.Loincloth

© 2022 - 2024 — McMap. All rights reserved.