Question

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!");
}
Était-ce utile?

La solution

I found the reason why my BBPreferencesWindowController did not manage the window well: in the XIB, the File's Owner window outlet wasn't linked correctly.

Fixing this resolved all other problems as well.

Thanks for your help!

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top