I have a NSPanel, which I want to set as keyWindow
so that it should post NSWindowDidBecomeKeyNotification
but, even on calling the makeKeyWindow
method, the notification is not being posted. Below is my code, but I am not able to figure out what is wrong with it:
newPanel = [[NSPanel alloc]initWithContentRect:windowRect
styleMask:NSUtilityWindowMask
backing:NSBackingStoreBuffered
defer:FALSE];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(test:)
name:@"NSWindowDidBecomeKeyNotification"
object:newPanel];
// Create a slider and add to the panel
NSSlider *slider = [[NSSlider alloc]initWithFrame:NSMakeRect(0, 0, windowRect.size.width, windowRect.size.height)];
[[newPanel contentView]addSubview:slider];
// Set window attributes
[newPanel setHasShadow:TRUE];
[newPanel setFloatingPanel:TRUE];
[newPanel setReleasedWhenClosed:TRUE];
[newPanel setHidesOnDeactivate:TRUE];
[newPanel setBecomesKeyOnlyIfNeeded:NO];
[newPanel makeKeyWindow];
[newPanel makeFirstResponder:slider];
[newPanel orderFront:sender];
Now when I call [newPanel makeKeyWindow];
the NSWindowDidBecomeKeyNotification should be posted and -(void)test:(NSNotification*)aNotification
should get called. But it isn't getting called.