In an effort to continue to learn how to use this new programming tool, I’ve created a new window in my project. I don’t want both windows to be visible at startup. In fact, for the time being, I’d like to know how to write the code to display either window so that later on I can have menu items the will show/hide windows as needed.
I have read about window controllers but I don’t know how to use them. I’m not sure if I understood what was being said in the docs. If I have windows: “xWindow” and “yWindow” in the same NIB do I create a window controller for each window or is that only for document-based apps where I might have more than one instance of “xWindow”?
Thanks,
Brad
You can use window controllers, but I haven’t done that yet, and it’s not necessary. You uncheck the visibleAtLaunch box in IB, to make it not show up when you start your program. You can then use xWindow’s makeKeyAndOrderFront_(me) to show it (and make it key) or xWindow’s orderOut_(me) to remove it.
Ric
Normally I write a class that controls a window (subclassing NSWindowController or NSWindow) and each class has it’s own nib file. Multiple windows controlled by one class is also wise to store all it’s windows in one nib but storing everything in a single nib gets very messy. I’m not sure what you mean with multi windows in a single nib but in my experience it’s almost a single window in a nib every time.
Surely that depends on the number of windows involved. For a small number, you can argue that separate nibs add unnecessary complication.
In many books about programming the examples are small and everything is done in the app delegate. Those examples are good and shouldn’t be coded differently but what I see is that many programmers stay in that model even when their application becomes bigger. I don’t understand the complications of multiple nibs because multiple nibs have only two main reasons, your project (including code) becomes much more human readable/friendly and you can exchange objects through different projects much easier.
I have always two nibs in my project, a mainMenu.nib (delete the default window) and make a window in a separate nib file. But these methods on small projects has nothing to do with complications only with a programmer’s preferences. A nib is a collection of serialised and archived objects and if it’s in one or separated over 10 files doesn’t really matter for the application. As long as the nib file is separated like your object model it is useful, more splitting in files is unnecessary.