views:

438

answers:

2

I usually don't use interface builder but from what I have gather it seems that interface builder if mostly for building self contained window. Is it possible to create a view with IB and then import this NIB file and use it as a subview?

+1  A: 

Yes. One of the templates is for a stand-alone view. If you have a nib already, you can drag any view from the Library panel into it.

Peter Hosey
+2  A: 

To add what Peter wrote: Yes you can, and it's also a fairly common method. For example, since 10.5 there's a class called NSViewController which does just that, and the interface builder has a template for that, too.

The steps are:

  1. Create a view in the nib file.
  2. Connect it to an outlet of the File's Owner.
  3. Load a nib, supplying the file's owner. If you use NSViewController, it's done by -initWithNibName:bundle:. In this case, the view is set at [self view].
  4. There's no step 4.

Slightly off topic, but I think it's worth spending some time for you to learn a bit of Objective-C and Cocoa program using it, before directly delving into the world of Cocoa bridges to other languages, be it RubyCocoa, PyObjC, or clozure-CL. That's because almost all of the Cocoa documentation, blog posts etc. is written for Objective-C. Objective-C is not a difficult language to learn, especially if you know OO and C already.

Yuji