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:
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 is FaceViewController
for testing purposes it should only display text for now.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.MyDocument.xib
I also add a Custom 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:
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 than NSView
?FaceViewController
in code or is it enough to drag it into either of my two .xibs?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.
You can create your FaceViewController either by adding one to the MyDocument.xib or by creating it with alloc, init.
To place your FaceView you'll have to do it programmatically, you can use
[customView addSubview:[FaceViewController view]];
of if you want to replace the view
[customView replaceSubview:oldView with:[FaceViewController view]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With