10

タイトルのように、[myWindowController showWindow:nil]動作しません。ここにあなたが知る必要があるかもしれないいくつかの事実があります:

  • 私のウィンドウコントローラー:KRAuthenticationWindowController
  • Interface Builderファイル:AuthenticationWindow.xib
  • ファイルの所有者はKRAuthenticationWindowController
  • windowコンセントは窓に接続されています
  • ウィンドウdelegateはファイルの所有者に接続されています
  • ウィンドウのVisible at launchチェックが外れている
  • ウィンドウRelease when closedもチェックされていません

私のコードを以下に示します。

// KRApplicationDelegate.m

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
    NSLog(@"%s",__PRETTY_FUNCTION__);
    KRAuthenticationWindowController *authWindowController = [[KRAuthenticationWindowController alloc] init];
    [authWindowController showWindow:nil];
    [[authWindowController window] makeKeyAndOrderFront:nil];
}

// KRAuthenticationWindowController.m

- (id)init {
    self = [super initWithWindowNibName:@"AuthenticationWindow"];
    if(!self) return nil;
    NSLog(@"%s",__PRETTY_FUNCTION__);
    return self;
}

- (void)loadWindow {
    [super loadWindow];
    [self.window setBackgroundColor:[NSColor colorWithDeviceWhite:0.73 alpha:1]];
    NSLog(@"%s",__PRETTY_FUNCTION__);
}

- (void)windowDidLoad {
    [super windowDidLoad];
    NSLog(@"%s",__PRETTY_FUNCTION__);
}

- (void)showWindow:(id)sender {
    [super showWindow:sender];
    NSLog(@"%@",self.window);
    NSLog(@"%s",__PRETTY_FUNCTION__);
}

私のコンソール出力:

2013-02-24 16:21:45.420 Application[3105:303] -[KRApplicationDelegate applicationDidFinishLaunching:]
2013-02-24 16:21:45.421 Application[3105:303] -[KRAuthenticationWindowController init]
2013-02-24 16:21:45.428 Application[3105:303] -[KRAuthenticationWindowController loadWindow]
2013-02-24 16:21:45.428 Application[3105:303] -[KRAuthenticationWindowController windowDidLoad]
2013-02-24 16:21:45.556 Application[3105:303] <NSWindow: 0x10016e860>
2013-02-24 16:21:45.556 Application[3105:303] -[KRAuthenticationWindowController showWindow:]

重要なことが欠けているだけだと思います。どんな助けでもいただければ幸いです。

4

1 に答える 1

34

authWindowController をインスタンス変数に変えてみてください。現在、これはローカル変数です。ローカル変数がなくなると、ウィンドウ コントローラーが解放され、ウィンドウが一緒に表示される可能性があるため、表示されることはありません。

于 2013-02-24T22:22:07.987 に答える