views:

488

answers:

2

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 does not make it in the foreground

+1  A: 

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];
}
rcw3
Ok, I tried to use that in a custom NSWindowController, but it had no effect. I've now removed my original NSBundle call and have:NSWindowController* awc = [[NSWindowController alloc] initWithWindowNibName:@"About"];[[awc window] makeKeyAndOrderFront:nil];And that spawns the window, but still does not make it in the foreground
Tegeril
+2  A: 

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];
}
Tegeril