开发者

How do I open an NSWindow and have the window selected and in focus?

开发者 https://www.devze.com 2022-12-29 20:34 出处:网络
I am trying to open a NSWindow using the following code: NSWindowController *window = [[NSWindowController alloc] initWithWindowNibName:@\"MainWindow\"];

I am trying to open a NSWindow using the following code:

NSWindowController *window = [[NSWindowController alloc] initWithWindowNibName:@"MainWindow"];
[window showWindow:nil];

The window opens okay but the previous window is still the mainWindow and in focus. I have tried the following code to force the main window and it doesn't work. The window still has a disabled title bar and isn't accepting开发者_开发技巧 key events etc.

[self.window makeKeyAndOrderFront:self];
[self.window makeMainWindow];

The only way I seem to be able to get the previous window to lose focus is if I close the window after calling showWindow: with [[NSApp mainWindow] close];

Any ideas?


makeKeyAndOrderFront: is the way to go. Are you sure that self.window and window refer the same object?


I resolved the issue by assigning the WindowController to the nib File Owner, instead of having a separate NSWindowController object within the nib.

0

精彩评论

暂无评论...
验证码 换一张
取 消