UISplitViewController preferredDisplayMode: wrong behavior

I have an app with basic details (I created it using the Xcode template and then modified it a bit) and I am trying to set the preferredDisplayMode property of the UISplitViewController to get this behavior:

UISplitViewControllerDisplayMode.PrimaryOverlay: The main view controller overlays on top of the secondary view controller, leaving the second view controller partially visible.

Thus, the master view controller must first sit above the detailed view controller and can be dismissed. I change this property in the app: didFinishLaunchingWithOptions :, full code:

 
// Inside application:didFinishLaunchingWithOptions:
// Override point for customization after application launch.
let rootViewController = window!.rootViewController as! UINavigationController
// The root view controller is a navigation controller that contains the split view controller
let splitViewController = rootViewController.viewControllers[0] as! UISplitViewController


      

let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem() splitViewController.delegate = self



splitViewController.preferredPrimaryColumnWidthFraction = 0.4 splitViewController.maximumPrimaryColumnWidth = 600 splitViewController.preferredDisplayMode = .PrimaryOverlay



return true



I have two problems: firstly, this is not the behavior I am getting. The main view controller is hidden when the app starts, and if I click on the left panel button item to show the master, it quickly pops up and disappears again. If I click on it another time, it appears without disappearing.
Second, I get a warning in the console:

2015-06-30 12:06:26.613 Presidents[29557:857547] Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x7b8be610>.

      

But I have no transitions in my code.

PS: This is from the book "Starting the Development of the Phone with Swift" by D. Mark, J. Nutting, K. Topley, F. Olsson, J. Lamarch, Chapter 11.

+3


source to share


1 answer


I got this working on my iPad app. In the Master View controller:

override func viewDidLoad() {
    super.viewDidLoad()

    splitViewController?.delegate = self

    let rect: CGRect = UIScreen.mainScreen().bounds
    if rect.height > rect.width {
        // am in portrait: trick to force the master view to open
        self.splitViewController?.preferredDisplayMode = .PrimaryOverlay
    }

      

Then later:



override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    self.splitViewController?.preferredDisplayMode = .Automatic

      

Now trying to figure out how to do this with an iPhone app ... EDIT: ah, see this previous answer

0


source







All Articles