How to reference XIB files from the parent XIB

If I create a custom UIView in ChildView.xib - how do I reference the MainWindow.xib file?

I tried dragging and dropping a UIView into MainWindow.xib and linking it to the same ChildView class. I made the owner of ChildView.xib ViewController from MainWindow.xib and in ChildView.xib, I connected the childView IBOutlet to the view, but when I run the application, the view in ChildView.xib does not load automatically.

Is it possible? At a basic level, I think I'm asking how to connect UIViews from individual XIB files to an IBOutlet link in another XIB ... for example MainWindow.xib.

FWIW, I know how to do this in code (manually creating an instance using NSBundle), but in this case I want to know how to do this completely in IB (Interface Builder).

+5
source share
1 answer

I experimented a bit with this and created a subclass of NSViewController with the corresponding XIB file. I can download this download automatically by placing an instance of the NSViewController object in the main XIB file and using the attribute inspector to set the name "Nib" to the XIB file name of the NSViewController subclass. This XIB file also contains, by default, one view object that you can configure in IB, or set a subclass type of a custom view.

However, it still requires one line of code to add the view controller view to the content view of the main window. (I did this as a delegate)

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [[self.window contentView] addSubview:myVC.view];
}

, NSViewController , XIB , NSViewController.

XIB XIB. , .

+2

All Articles