Question

I'm have done some development on iOS using Storyboards. Now I'm building on app for Mac OS X and it seems that an equivalent for Storyboards does not exists.

For instance, I'm need to build some kind of wizard, which contains four different windows or views (step 1 to 4).

Currently I've created one Window xib (the standard MainMenu.xib), containing a window with the first view, and three other custom views. Using this approach, I can create outlets and actions, making me able to change the contentView of my window, e.g. when clicking an button. This seems as a fair solution, and my views are all grouped cleanly inside a single xib. But this also cause that the logic for all the view should be handled by the same File's Owner, right? For instance saving the settings on each step and controlling the interaction between the different views.

How is the preferred way to handle a situation like this? Should I instead create four different windows, and maybe in four different xib-files? If you know an sample project somewhere from the internet showing how to handle multiple windows, please give me a hint.

Was it helpful?

Solution

You can make use of the NSViewController class for this purpose. Each view controller will be responsible of loading a xib associated with it and all logic associated with the views can go inside the controllers (Same as in iOS). The MainMenu.xib can now load appropriate views after initialising the required view controllers.

Here is a sample app for your reference. https://developer.apple.com/library/mac/samplecode/ViewController/Introduction/Intro.html

OTHER TIPS

In xcode, go to File->New->New File Add an objective C class and set it to subclass of "NSViewController". This will itself create yourController.h, yourController.m and yourController.xib. Now you can keep your view and its controller class seperate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top