1
votes

I tried to implement UISplitViewController by following steps in 《iOS 8 by tutorial》。

The ducoment said if I return yes in splitViewController:collapseSecondaryViewController:ontoPrimaryViewController: method, the split view controller will shows only the content from its primary view controller.

But in my project, the split view controller shows both primary and secondary view controller in collapsed interface no matter I return true of false in this method. And the most wired thing is that this method is only called once when the app begins running.

Here is my custom SplitViewController which subclasses to UISplitViewController:

import UIKit

class SplitViewController: UISplitViewController, UISplitViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.delegate = self
    }

    // MARK:- UISplitViewControllerDelegate
    func splitViewController(splitController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {

        // We don't want anything to happen. Say we've dealt with it
        return true
    }
}
1

1 Answers

0
votes

I found I needed to add "self.preferredDisplayMode=.primaryOverlay" to my ViewDidLoad.

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
    self.delegate = self
    self.preferredDisplayMode = .primaryOverlay
 }

The preferredDisplayMode has some other options to customize the initial behavior you can toy with to get your preferred look and feel.

Note this is for iPhone, Compact Width. Test also on an iPad as it behaves differently (landscape vs. portrait).