Show master view first

On an iPhone (compact layout), UISplitViewController likes to show the detail view when the app starts. To make the master view the first one shown, do this:

Swift 2.3
class MyMasterTableViewController: UITableViewController, UISplitViewControllerDelegate {
    private var collapseDetailViewController = true

    override func viewDidLoad() {
        super.viewDidLoad()

        splitViewController?.delegate = self
    }

    // MARK: - UITableViewDelegate

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        collapseDetailViewController = false
    }

    // MARK: - UISplitViewControllerDelegate

    func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
        return collapseDetailViewController
    }
}

h/t

  • http://nshipster.com/uisplitviewcontroller/