tags:

views:

79

answers:

1

When creating a nib, I have 2 types to create, a WindowNib or a ViewNib. I see the difference is, the window nib has a window, and a view.

How do I load a view nib into another window? Do I have to create a WindowController and add a window then load the nib in the window?

+3  A: 

Typically, you should have a Controller for each NIB. So in the case of a Window NIB you would have an NSWindowController subclass as the File's Owner. Similarly for a View NIB you would have an NSViewController subclass as the File's Owner. In the case you present the NSWindowController subclass would instantiate the NSViewController subclass (passing it the appropriate View NIB) and then attach the NSViewController's view property to the window's view hierarchy.

Example in your Window Controller's awakFromNib method you would have the following:

- (void) awakeFromNib {
    _viewController = [[MyViewController alloc] initWithNibName: @"MyView" bundle: nil];
    [[[self window] contentView] addSubView: [_viewController view]];
}

You could also place this code in the windowDidLoad method of your NSWindowController subclass.

Bryan Kyle