Search code examples
iosswiftuisplitviewcontroller

UISplitViewController display wrong ViewController on launch


I have a fully functional Address book app (from Lynda.com called iOS Address Book App: Hands On) that utilizes a UISplitViewController.

I want to implement this Address Book app into my existing Tab bar app.

I have moved all over and the most all runs well. (Storyboard items and all ViewControllers, except the AppDelegate).

The only issue I have is when I select the Address Book Tab (on home screen), it displays the detailsViewController as the default view. I can hit the back button that takes me to the Master screen and all works fine. I just need it to display the Master View as the initial screen.

Clearly, it is a setting issue as it works fine as a stand alone.

Willing to post any code necessary to help, but not sure which VC to post.

Here are some images to show what I am referring to:

Tab bar

Tab bar

Selecting "Buddies" takes me here, to the DetailViewConroller

enter image description here

Instead of here, the MasterViewController

enter image description here

Hopefully, someone has seen this before.

MasterViewController


Solution

  • Found it. Posting in case someone stumbles across this same issue. Apparently, the DetailViewController is the default view while in portrait (I assume non iPad portrait). To change the initial screen do the following to the MasterViewController.swift (or the view controller you use to control the UITableView)

    class MasterViewController: UITableViewController, UISearchResultsUpdating, UISplitViewControllerDelegate {
    
        private var collapseDetailViewController = true
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
        splitViewController?.delegate = self
    
    }
    
    
    
    func splitViewController(splitViewController: UISplitViewController, collapseSecondaryViewController secondaryViewController: UIViewController, ontoPrimaryViewController primaryViewController: UIViewController) -> Bool {
        return collapseDetailViewController
    }