user2698617 user2698617 - 1 year ago 82
Swift Question

Second Master-Detail Scheme Does Not Load Correctly in SplitViewController

I have a master-detail application setup in a split view controller that is basically Swift standard code. With the initial master-detail scheme it works as expected.

I want to load a Second Master with it's Second Detail in the left and right panes of the split view controller. With one major exception it is working as expected. The exception is that the second detail view only covers the second master in the left pane. The second detail does not load in the right pane.

Here's the issue graphically. The first master-detail scheme:
enter image description here

Then when the second master is launched:
enter image description here

Then when a cell is tapped in the second master:
enter image description here

I load the second master from a MVC1 button with a simple storyboard segue, though I've done it programmatically as a delegate. Nothing has worked to show master 2 on the left and detail 2 on the right. In all cases, I have tried the segue as Show and as Show Detail. I can't discern a difference in the app behavior.

enter image description here

For the segue from MVC2 to DVC2:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "showKeywordDetail" {

if let indexPath = self.tableView.indexPathForSelectedRow {

let object = self.fetchedResultsController.objectAtIndexPath(indexPath) as! Keyword
let controller = segue.destinationViewController as! KeywordDetailViewController

controller.detailItem = object
//controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = false
controller.sentBy = "showKeywordDetail"

}//if let indexPath

} else if segue.identifier == "addKeyword" {

//bunch more code for other cases


Any guidance would be appreciated.

Answer Source

The key to this solution seems to be creating a separate "non-connected" master detail scheme.

On the original master, place a button with an action:

@IBAction func doCodeKeywordPush(sender : AnyObject) {
 self.navigationController!.pushViewController(self.storyboard!.instantiateViewControllerWithIdentifier("KeywordTableViewController") as! UITableViewController, animated: true)


Then make the second master-detail scheme a stand alone set in the storyboard. Embed the second master view controller in a navigation controller. Create a segue from the second master tableViewCell to the second detail view controller. There should be no segue or connection between the button and the second group.

Finally, configure the second master to second detail segue as any other setup.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download