Objective-c – NSWindow makeKeyAndOrderFront makes window appear, but not Key or Front

cocoamacosobjective c

makeKeyAndOrderFront is not making my NSWindow key or front.

My app does not have a main window or menubar, which may be part of the problem?

IBOutlet NSWindow *loginWindow;
//(connected in Interface Builder to the NSWindow)

The NSWindow has "visible at launch" and "release when closed" both unchecked.

Then:

- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
    [loginWindow makeKeyAndOrderFront:self];
}

This does open the window. (commenting it out results in no window being opened).

However:

  • It appears behind the Xcode window (not front).

  • It appears to recieve mouse focus, but will not take keypresses in the textfields the window contains. The keypresses are sent to Xcode.

  • It appears in the Expose grid when Expose is activated. But I cannot click the window to select it in Expose… it won't come to the front.

Why isn't my Window working?

Best Answer

Try calling this method [NSApp activateIgnoringOtherApps:YES];. This should make it the active application.

Related Topic