質問

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;
}

makeKeyAndOrderFront の前に [secondWindowController showWindow:self] を置いてみましたが、違いはありません。

役に立ちましたか?

解決

SecondWindowControllerのウィンドウアウトレットがNIBのウィンドウに接続されていることを確認しましたか?アウトレットが接続されていない場合でも、NIBをロードするだけでウィンドウを表示できます。

他のヒント

ボーダレスウィンドウを使用していますか?その場合、canBecomeKeyWindowをオーバーライドしてYESを返す必要があります

これを試してください:

if (!secondWindowController)
    secondWindowController = [[SecondWindowController alloc] init];    
NSApplication *thisApp = [NSApplication sharedApplication];
[thisApp activateIgnoringOtherApps:YES];
[[secondWindowController window] makeKeyAndOrderFront:self];
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top