This is very helpful, but I think the explicit code that’s missing is the XIB method for all that is explained programmatically. Both your book and O’Reilly’s book suggest an elaborate view swapping class, before explaining the individual commands for perhaps other implementations to be created. What’s not clear to me is this:
I name a XIB “MainWindow.” I want that attached to an NSWindow *mainWindow object without it being the default window. How?
I name a XIB “MainView.” I want that attached an NSView *mainView to my *mainWindow object at a particular x,y. How?
After these basic questions are answered, I’m ready to bake all the fundamental code into a tutorial that handles swapping views based on an array of view objects that swap in and out. The reality is that I might have a screen that has multiple views such as dialog boxes that will float over other views (I make video games, and don’t want actual Window objects messing up the experience).
I found this example in O’Reilly’s book:
controller = [[MyWindowController alloc] initWithWindowNibName:@"XIBName"];
However, when it comes to the same sample code for adding and showing a view, we’re automatically building an all purpose hide / show’er, which is really for something more like an iOS app than a multi-view OSX app. There is a ton of philosophy and theory, but very little actual code for these basic elements. It seems so fundamental, I was surprised not to see the code. I spent most my time in the Custom Views chapter with a lot of examples of how to use the IB to make a XIB, and the methods that a View can take, but not the sample code for implementing them outside of a default window derived from the AppDelegate / .info file.
On page 241, we get three methods that a View can take…no example.
On pages 242 to 245, we get examples of how to build a XIB view using IB.
On pages 246 to 248, we get programmatic examples of drawing a rectangle…still no examples of how to use the XIB view from the previous section.
On pages 248 to the end of the chapter, we get examples of how to add more shapes programmatically.
The chapter ends without the fundamental question answered, how does one use a XIB view created in IB?
For some reason, this is nearly undocumented in every book on OSX. Again, I could be missing a bigger picture that makes my confusion moot. I’m eager to discover that oversight.