NSWindow focus

Discussion in 'Mac Programming' started by ajbrehm, Aug 27, 2008.

  1. macrumors 6502

    Joined:
    Aug 14, 2002
    Location:
    Zurich, Switzerland
    #1
    I have an application with two XIB files.

    One contains an NSWindow that is displayed when a certain menu item is clicked in the menu defined by the XIB file.

    This works.

    However, the new window doesn't have focus and none of the methods like makeKeyWindow etc. seem to change that fact when called. How do I change the focus to another window?

    Also, how can I make an NSWindow modal?

    Thanks in advance.
     
  2. thread starter macrumors 6502

    Joined:
    Aug 14, 2002
    Location:
    Zurich, Switzerland
    #2
    Turns out there is a NSApplication runModalForWindow: method that makes an NSWindow modal. I just have to look around for my NSApplication object. main() probably created one, probably NSApp or so.

    From the documentation:

    I still don't know how to set focus to the window though.
     
  3. macrumors 601

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    I assume you mean makeKeyAndOrderFront? That should work. Make sure your connection is made and that the window is valid just before you try to make that call. But yes, if you started a modal window somewhere, that'll probably block it.
     
  4. thread starter macrumors 6502

    Joined:
    Aug 14, 2002
    Location:
    Zurich, Switzerland
    #4
    I tried makeKeyAndOrderFront but that didn't change anything. The window was in front of the other window but didn't have focus (and didn't get it from makeKeyAndOrderFront either).

    The connection is made and the window is valid and I can interact with it otherwise.
     
  5. thread starter macrumors 6502

    Joined:
    Aug 14, 2002
    Location:
    Zurich, Switzerland
    #5
    Turns out the only interaction that works is closing the window and having the delegate react to it.

    I cannot write text into textfields and none of the methods to focus the window (or change its order or whatever) have any effect.

    The connections between the class and the xib file are all set up.

    Is there anything else I have to do?

    I found a few Web pages that explain how to load a window from a second nib file but they are end when they finished explaining what I figured out myself, how to load the nib file and display the window in it. None continue explaining how to interact with the window.

    The connections I defined and connected don't work. Any ideas?
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    Is the window a borderless window, or a normal window? Can you post a screenshot? Also make sure your other window doesn't have the "Visible at launch" checkbox enabled in IB.
     
  7. thread starter macrumors 6502

    Joined:
    Aug 14, 2002
    Location:
    Zurich, Switzerland
    #7
    I can post a screenshot later.

    The other window probably has "Visible at launch" set, since it is the main window and supposed to be visible at launch.

    Both windows are normal windows and can be resized and minimised.
     

Share This Page