我正在尝试使用 makeKeyAndOrderFront 从另一个窗口打开一个窗口。新窗口出现,但没有获得焦点。
主窗口的代码是:
#import "SecondWindowController.h"
@implementation FirstWindowController
-(IBAction)showSecondWindow:(id)sender
{
if (!secondWindowController)
secondWindowController = [[SecondWindowController alloc] init];
[[secondWindowController window] makeKeyAndOrderFront:self];
}
SecondWindowController 是一个 NSWindowController,如下:
@implementation SecondWindowController
-(id)init
{
if (![super initWithWindowNibName:@"SecondWindow"])
return nil;
return self;
}
我也试过把它放在[secondWindowController showWindow:self]
前面,makeKeyAndOrderFront
但它没有任何区别。