I’m creating a test application, trying to use MVC, for Mac.
I have created 5 nib files, each with different windows, and class files for each nib.
What do I do so that when you press a button on the MainMenu.xib, it opens a new view?
I’ve seen use of the initWithNibName:, for iOS, but can’t find how this works on a Mac. Or am I going about this the wrong way? If so, how do you manage different views and classes in a Mac application with Xcode?
Because you mentioned “I have created 5 nib files, each with different windows, and class files for each nib.” I’m assuming you have 5 different windows (not views) and want to open them on button press.
Each window nib file is controlled by a
NSWindowController, which would be the C in MVC. To actually load a nib file (programmatically) you assign it aNSWindowController; theNSWindowControllerin OS X is comparable to theUIViewControlleron iPhone.Then you can open/close the window the NSWindowController manages.
[controller showWindow:nil]to show the window[controller.window makeKeyAndOrderFront:self]to make the window the key window.You’re probably intending to do something else though, which is to keep the same window but to switch the content view of that window. In that case you’d want nib files that contain views (and use NSViewControllers to load them), not windows (because having windows would be redundant).
But even if you stick with windows, to replace the contentView:
You should read ALL the documentation Apple has to offer on Windows, views, and applications.