I have a custom NSWindow class that has the following methods:
- (void)setupWindowForEvents{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignMainNotification object:self];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:self];
}
-(void)windowDidResignKey:(NSNotification *)note {
NSLog(@"notification");
[self close];
}
I call [_window setupWindowForEvents];
but the windowDidResignKey
never gets called.
This is how I call my NSWindow: when the status bar item is clicked I makeKeyAndOrderFront
and the Window is displayed right beneath the status bar item, like this:
Any ideas why the I don't get any notification when the window loses focus? I've used both NSWindowDidResignMainNotification
and NSWindowDidResignKeyNotification
to see if any of these worked, but none is working.
NSWindowDidResignMainNotification
andNSWindowDidResignKeyNotification
? – Alternative