Change views inside NSSplitViewController

I am trying to port my Objective-C and now improve my Swift knowledge to a Mac OS X app. Steep learning curve!

I am trying to load NSSplitViewController

with different views in the "detail view" depending on the buttons clicked on the "main view" if you do. Subsequent lessons and a search for hours brought me to zero.

I currently have:

import Cocoa

class MainSplitView: NSSplitViewController, BlissWindowDelegate {

    var masterViewController: vcMainMenu {
        let masterItem = splitViewItems[0] as! NSSplitViewItem
        return masterItem.viewController as! vcMainMenu
    }

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

    }

    func userDidSelectFunction(function: String) {

        switch function {
        case "app":
            println("You have selected to load the appointment screen")
        case "cust":
            println("You have selected to load the customer screen")
        case "login":
            println("I think I am here and you've clicked login?")
            let detailItem = splitViewItems[1] as! NSSplitViewItem

            // Trying to load the views here ... but no idea how to

        case "admin":
            println("You've clicked admin")
        default:
            println("Nothing here ...")

        }

    }

} 

      

I use BlissWindowDelegate

to indicate which button was clicked. Then I try to load in splitViewItem[1]

different views from the storyboard. But no luck. Can anyone point me in the right direction please? Even for a decent link? Nothing on Google seems to be helping.

Thank.

+3


source to share


1 answer


Since it looks like you have a certain set of detailed panels to show, using NSTabViewController

is probably the best way to accomplish this.

Basically, yours NSSplitViewController

has two children: the main view controller and the NSTabViewController

. And the tab view controller has its own children for each of the detail panes. Since the table view controller does not have to present its own tab selection user interface (the master panel does), you must set tabStyle

as .Unspecified

. The storyboard will look something like this:



Storyboard with NSSplitViewController and NSTabViewController

Your MainSplitViewController

will also be a reference to the Controller tab presentation detailController

. Then, userDidSelectFunction()

you will set the detailController parameter selectedTabViewItemIndex

to match the corresponding detail pane. NSTabViewController

will take care of the transition of the view, including animation between the panels, if necessary.

+12


source







All Articles