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开发者_如何学Go limit the number of visible windows?
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];
}
精彩评论