views:

17

answers:

1

I have a button in my application, when you click it it opens a new NSWindow. However, if you keep on clicking it it will open another NSWindow. How can I limit the number of visible windows?

+2  A: 

Disable the button. If you have a button that creates a new window, then it should create a new window. If you don't want the user to create a new window, don't let them click the button.

edit if you're dealing with something like a preferences window, then you should probably be using an NSWindowController subclass to control the window. Clicking the button should essentially do (preferencesWindowController is an ivar):

- (void) showPreferences:(id)sender {
  if (preferencesWindowController == nil) {
    preferencesWindowController = [[PreferencesWindowController alloc] init];
  }
  [preferencesWindowController showWindow:sender];
}
Dave DeLong
It's more like a preferences window.
Matt S.
@Matt S. edited answer
Dave DeLong