How to switch between NSViewControllers using NSPageController?

I was not lucky to find any examples on the Internet that exactly match what I'm trying to do. I am trying to use NSPageControllerto view and switch between several NSPageControllers. My steps.

  • I am creating a new fast OS X project
  • I add an object to ViewControllerand make it from a class NSPageController.
  • I add two buttons: one is a "Next" label, and the other is a "Back" label for transitions.
  • I bind buttons to an object NSPageControllerlike navigateForward and navigateBack.
  • I create an output in a custom class NSViewControllerfor the object NSPageControllerand add special delegate methods NSPageController.
  • I add two additional view controllers to the storyboard and create an identifier for them for the link in my custom controller class of the form: Wizard1, Wizard2.

    import Cocoa

    class ViewController: NSViewController, NSPageControllerDelegate {

    @IBOutlet var myPageController: NSPageController!
    override func viewDidLoad() {
        super.viewDidLoad()
        let vc1: AnyObject? = self.storyboard!.instantiateControllerWithIdentifier("Wizard1")
        let vc2: AnyObject? = self.storyboard!.instantiateControllerWithIdentifier("Wizard2")
        self.myPageController.arrangedObjects.append(vc1!)
        self.myPageController.arrangedObjects.append(vc2!)
        // Do any additional setup after loading the view.
    }
    override init?(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        myPageController = NSPageController()
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil?)
    }
    
     required init?(coder aDecoder: NSCoder) {
    myPageController = NSPageController()
    super.init(coder:aDecoder)
    }
    
    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }
    
    func pageController(pageController: NSPageController, identifierForObject object: AnyObject!) -> String! {
        return "View"
    }
    
    func pageController(pageController: NSPageController, viewControllerForIdentifier identifier: String!) -> NSViewController! {
        let vc1: AnyObject? = self.storyboard!.instantiateControllerWithIdentifier("Wizard1")
        return vc1 as NSViewController
    
    }
    func pageController(pageController: NSPageController, prepareViewController viewController: NSViewController!, withObject object: AnyObject!) {
        viewController.representedObject = object
    }
    func pageControllerDidEndLiveTransition(pageController: NSPageController) {
        pageController.completeTransition()
    }
    func pageControllerWillStartLiveTransition(pageController: NSPageController) {
    self.presentViewControllerAsModalWindow(self.storyboard?.instantiateControllerWithIdentifier("Wizard2") as NSViewController)
    
    }
    

    }

Error clicking the following button:

-[NSNib initWithNibNamed:bundle:] could not load the nibName: NSPageController in bundle (null).
+4
source share
2 answers

Perhaps you are trying to load a thread with the wrong name in AppDelegate.mor wherever you initialize your page controller.

Otherwise, you skipped creating the .xib file and name it NSPageController. When creating a Cocoa Touch Class, there is a checkbox to also create an xib file for your class, if necessary.

0
source

:

myPageController = NSPageController()

, . NSViewController , . "NSPageController".

0

All Articles