PDA

View Full Version : NSWindow can't get focus




Vizin
Oct 12, 2009, 11:30 PM
Hi, I'm having trouble creating a new NSWindow. The window appears but it can't get focus. Here's what I'm trying:

EditorWindowController *windowController=[[EditorWindowController alloc] initWithWindowNibName:@"Editor"];
[[windowController window] becomeKeyWindow];

I've also tried using becomeMainWindow, but nothing works.

I've googled the problem extensively and found some other people have had the same issue, but I couldn't find any answers.

Anyone know what might be wrong? This is one of my first cocoa for mac apps, most of my cocoa experience is for iPhone OS, so I might be understanding something wrong.



kainjow
Oct 13, 2009, 02:43 PM
From the docs for becomeKeyWindow:
Invoked automatically to inform the window that it has become the key window; never invoke this method directly.

What you want is makeKeyAndOrderFront:

[[windowController window] makeKeyAndOrderFront:nil];

However, if your EditorWindowController class is a subclass of NSWindowController (which it probably should be), you can use this instead;
[windowController showWindow:nil];

Vizin
Oct 13, 2009, 02:52 PM
Thanks for the help, but neither of those worked. The original window keeps focus.

kainjow
Oct 13, 2009, 04:02 PM
You might not have connected the window in the nib, and possibly have the "Visible At Launch" checkbox enabled for the window in IB. I'd double-check these.

Vizin
Oct 13, 2009, 04:43 PM
You might not have connected the window in the nib, and possibly have the "Visible At Launch" checkbox enabled for the window in IB. I'd double-check these.

Oh god. Somehow I knew it was going to be something incredibly simple that I spaced out on.

Thanks a lot. :) I can't believe I missed that.