NSWindow can't get focus

Discussion in 'Mac Programming' started by Vizin, Oct 12, 2009.

  1. macrumors 6502a

    Joined:
    Jun 30, 2007
    #1
    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.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    From the docs for becomeKeyWindow:
    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];
     
  3. thread starter macrumors 6502a

    Joined:
    Jun 30, 2007
    #3
    Thanks for the help, but neither of those worked. The original window keeps focus.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. thread starter macrumors 6502a

    Joined:
    Jun 30, 2007
    #5
    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.
     

Share This Page