I have a NSWindowController subclass, BBPreferencesWindowController
@implementation BBPreferencesWindowController
- (NSString *)windowNibName
{
return @"PreferencesWindow";
}
...
And a function in my AppDelegate that can open the window in the "PreferencesWindow.xib" through this controller.
This function is called from an NSMenuItem, attached to an NSMenu under an NSStatusItem item in the system menu bar.
@property (strong) BBPreferencesWindowController *preferencesWindow;
...
- (void)openPreferences
{
if (self.preferencesWindow == nil)
{
self.preferencesWindow = [[BBPreferencesWindowController alloc] init];
}
[self.preferencesWindow showWindow:self];
NSLog(@"%@", self.preferencesWindow.window.isVisible ? @"YES" : @"NO");
}
The window is showed fine the first time I click the NSMenuItem (although the NSLog line logs "NO"), but when I close the window and then try to re-open it by click on the NSMenuItem for a second time, the window won't open.
What am I missing?
Thanks!
Edit:
BBPreferencesWindowController doesn't have a custom init method. It does have a custom awakeFromNib (that gets called the first time)
- (void)awakeFromNib
{
[super awakeFromNib];
NSLog(@"Loaded!");
}
self.preferencesWindowis nil, which it won't be unless you clear it for some reason. Are you doing so when the window closes? - gaigeAppDelegateor destroy the controller inwindowDidClose? - brtdv