Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Vizin

macrumors 6502a
Original poster
Jun 30, 2007
532
0
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:mad:"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.
 
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:

Code:
[[windowController window] makeKeyAndOrderFront:nil];

However, if your EditorWindowController class is a subclass of NSWindowController (which it probably should be), you can use this instead;
Code:
[windowController showWindow:nil];
 
Thanks for the help, but neither of those worked. The original window keeps focus.
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.