I have been struggling quite a bit with this problem and I can't seem to figure it out by myself.
This is the situation: I want to have a custom Nib-based view, with its own ViewController. I then want to add this view to a window. Therefore the window should contain my custom view.
So I go about and create a very simple example like this:
- In Xcode 4 I create a new blank document-based Cocoa application
- I create a new Cocoa Class which should extend from
NSViewController
(which causes the nib to be created along with the .h and .m file. The name of the created .h, .m und .xib file isFaceViewController
for testing purposes it should only display text for now. - I open the
NSViewController.xib
in InterfaceBuilder and add a multi-line text component and place it in the custom view, which is already in the xib file. I make the text span the whole view. - In
MyDocument.xib
I also add aCustom View
place holder, which should be replaced with my custom FaceView.
From this starting point on, everything I tried to include the created View + ViewController on my MyDocument.xib
failed and the area where my text should be shown remains empty (just like the background of the underlying window.
So my question really is what I need to do, so that my FaceView gets loaded into the Custom View which I placed on MyDocument.xib
. Here are some things which are unclear to me:
- The custom View extends from
NSView
so I wanted to change this to my FaceView but the view does not exist as a class but is defined in InterfaceBuilder in the xib, do I need to set this to anything other thanNSView
? - Do I have to alloc, init the
FaceViewController
in code or is it enough to drag it into either of my two .xibs? - Can I use InterfaceBuilder to place my FaceView or do I have to do this programmatically?
I really thought that creating a custom view like this would be a piece of cake but it turned out quite the opposite so far, so any help would be greatly appreciated.