Steve McLeod
Steve McLeod

Reputation: 52458

In a Cocoa OS X app, how can I make two windows open at startup?

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?

Upvotes: 3

Views: 1115

Answers (1)

hamstergene
hamstergene

Reputation: 24439

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.

Upvotes: 3

Related Questions