I wrote a menu application that has no persistent window or standard menu. When another application has focus and I use the menulet to trigger a window to be opened, it appears behind the foreground application (but above anything else that is present on the screen).
Basically...
-(IBAction)aboutWindow:(id)sender {
[NSBundle loadNibNamed:@"About" owner:self];
}
Can anyone point me in the right direction so I can get this window to appear above all other applications when it is initially spawned?
[Edit]
I have tried using a custom NSWindowController with the window linked up, and awakeFromNib calling a makekeyandorderfront method, but that wasn't doing anything.
I now have instead of the NSBundle call:
NSWindowController* awc = [[NSWindowController alloc] initWithWindowNibName:@"About"];
[[awc window] makeKeyAndOrderFront:nil];
And that spawns the window, but still do开发者_运维技巧es not make it in the foreground
Figured it out. Nothing was wrong with the Window, it was the Application. It was not in the foreground because of its nature as a menulet with no windows before this one is spawned. Final code:
-(IBAction)aboutWindow:(id)sender {
NSWindowController* awc = [[NSWindowController alloc] initWithWindowNibName:@"About"];
[[awc window] makeKeyAndOrderFront:nil];
[[NSApplication sharedApplication] arrangeInFront:nil];
}
You could try makeKeyAndOrderFront:
For example, in the About window's controller - assuming the controller had a reference to the window as myWindow
:
- (void)awakeFromNib
{
[myWindow makeKeyAndOrderFront:nil];
}
精彩评论