Cocoa: Multiple NIB application


  • Windows lazy-loading: shorter launch time
  • Easier NIB localization
  • Clean and tidy


A good example from Apple:


Here are some missing notes:


No need to create a controller's instance here. Outlets and actions connections have to be made to File's Owner, which is a SMWSecondWindowController (by setting its custom class).

That's understandable from the way SecondWindow.nib is initialized:

_controller = [[SMWSecondWindowController alloc] initWithWindowNibName:@"SecondWindow"];  


File's Owner has to have its delegate outlet set to the controller instance SMWAppDelegate.

So SMWAppDelegate is the application delegate, and then can this code from SMWSecondWindowController.m work:

[[NSApp delegate] answerQuestion:[questionField stringValue]];


How to keep bindings working across multiple NIB files? One solution is making your main controller instance the application delegate (like with SMWAppDelegate above). So you can add this accessor to your window controller subclass (SMWSecondWindowController in the example above):

- (Controller *)controller
        return [NSApp delegate];

Then you can bind anything from your new NIB to File's Owner and set the keyPath to something like that:


In this example, addressesArrayController is an oulet of your main controller class connected to an NSArrayCOntroller.