4

I have a storyboard with a window controller. That window controller has a NSToolbar with 2 NSToolbarItems, view1 and view2. This is the code for the WindowController:

import Cocoa

class MainWindow: NSWindowController {

    override func windowDidLoad() {
        super.windowDidLoad()

    }


    @IBOutlet var toolbar: NSToolbar!

    @IBAction func view1(sender: AnyObject) {
        ViewController().changeView("View1")
    }

    @IBAction func view2(sender: AnyObject) {
        ViewController().changeView("View2")
    }
}

I also have a view controller (ViewController) that is loaded on start. This is where the code is for two more view controllers (View1) and (View2)

import Cocoa

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override var representedObject: AnyObject? {
        didSet {

         }
    }

    func changeView (kString:NSString) {
        let kView1:NSViewController = NSStoryboard(name: "Main", bundle: nil)?.instantiateControllerWithIdentifier("View1") as NSViewController

        let kView2:NSViewController = NSStoryboard(name: "Main", bundle: nil)?.instantiateControllerWithIdentifier("View2") as NSViewController

        var currentViewController = kView1

        switch kString {
        case "View1":
            currentViewController = kView1
        case "View2":
            currentViewController = kView2
        default:
            currentViewController = kView1
        }

        self.view.addSubview (currentViewController.view)
    }

}

Here is my storyboard layout: (It seems I can't post images, my reputation is to low) I hope you can understand

[MainWindow] -> [SplitViewController] -> [SideBar (Not used yet)]

---------------------------------------------> [ViewController]

There are then two stand alone view controllers in the storyboard, not connected to anything. View1 and View2

View1 and View2 both have storyboard ID's View1 and View2 respectively.

When running the app and clicking one of the view buttons on the toolbar, I get an error message in the console:

2015-03-19 10:35:31.448 ToolbarTest[16032:2922107] -[NSNib initWithNibNamed:bundle:] could not load the nibName: ToolbarTest.ViewController in bundle (null).

What am I doing wrong?

Carl
  • 43
  • 6

0 Answers0