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

ajbrehm

macrumors 6502
Original poster
Aug 14, 2002
341
0
Zurich, Switzerland
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.
 

ajbrehm

macrumors 6502
Original poster
Aug 14, 2002
341
0
Zurich, Switzerland
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:

runModalForWindow:

Starts a modal event loop for a given window.

- (NSInteger)runModalForWindow:(NSWindow *)aWindow
Discussion

Until the loop is broken by a stopModal, stopModalWithCode:, or abortModal message, the application won’t respond to any mouse, keyboard, or window-close events unless they’re associated with aWindow.

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

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
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.
 

ajbrehm

macrumors 6502
Original poster
Aug 14, 2002
341
0
Zurich, Switzerland
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.

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.
 

ajbrehm

macrumors 6502
Original poster
Aug 14, 2002
341
0
Zurich, Switzerland
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?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

ajbrehm

macrumors 6502
Original poster
Aug 14, 2002
341
0
Zurich, Switzerland
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.