Search code examples
swiftuisplitviewcontrollermaster-detail

MasterViewController BarButton missing after Show Detail Segue is triggered


I'm still pretty new to Swift and doing little personal projects to aid in my understanding of things.

Right now, I'm using the Master-Detail Application as the template. On the MasterViewController, it is a dynamic TableViewController.

What I'm trying to achieve is when I tap on any of the cells, the MasterViewController will show another list of navigation ( which I have managed to do so using Push segue ), and on the DetailViewController, instead of calling DetailViewController, it is currently calling ContentsViewController which is a ViewController with TabBar ( which I also have got it hooked up using Ctrl Click on the Cell and use Accessory Action -> Show ).

A snippet of the source code that triggers the segue

MasterViewController.swift

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "showContentDetailSegue" {
        if let indexPath = self.tableView.indexPathForSelectedRow() {
            performSegueWithIdentifier ("ContentDetailSegue", sender: self)
        }
    }
}

Right now, ContentsViewController has no problem being displayed. However, the BarButton on the top left no longer has the Master BarButton that toggles the MasterViewController.

I've also tried self.presentViewController but it will replace the whole screen which isn't what I have in mind as I wanted to keep the Split View intact.

Where did I go wrong? Any help is appreciated.


Solution

  • Ok, found another issue when attempting to click on other tabs whereby the Master on the top left will be amiss until I click on the first tab.

    To resolve this, I used what is being suggested in http://nshipster.com/uisplitviewcontroller/

    Include the following codes in the respective swift files that is hooked up with the storyboard xyzViewController

    navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
    navigationItem.leftItemsSupplementBackButton = true