3

My OS X app has two windows. I've put one in MainMenu.xib, and the other in SecondaryWindow.xib.

When I run my app, the window in MainMenu.xib shows. I also want the second window in SecondaryWindow.xib to show at startup. How do I achieve this? Was it a good idea to use a separate xib file for the second window?

Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
  • I'm sure you can do it programmatically. In your `awakeFromNib` delegate method add the two lines from [this answer](http://stackoverflow.com/a/5548528/377628). –  Jul 20 '12 at 14:56

1 Answers1

3

If you'd like to do it without a line of code, add NSWindowController object to MainMenu.xib and write second xib's name to it's property. When MainMenu.xib is loaded, this window controller will be created and will load the second xib, causing the second window to pop up if it's configured to be visible on startup.

Or do it programmatically from e.g. applicationDidFinishLaunching: or awakeFromNib:.

Besides being an instrument for breaking UI into independent modules, separate xibs make it possible, for example, to unload some of them and save memory (e.g. when window is closed), or load one multiple times.

In your case, if both windows always have to be in memory, you can safely keep them in the same xib.

hamstergene
  • 24,039
  • 5
  • 57
  • 72