2013-02-24 13 views
10

Wie im Titel funktioniert [myWindowController showWindow:nil] nicht. Hier sind einige Fakten, die Sie benötigen wissen:NSWindowController showWindow: Nichts tut nichts

  • Mein Fenster Controller: KRAuthenticationWindowController
  • Interface Builder-Datei: AuthenticationWindow.xib
  • Datei-Besitzer ist KRAuthenticationWindowController
  • window Auslass mit dem Fenster verbunden ist
  • Fensters delegate ist mit dem Besitzer der Datei verbunden
  • Fenster Visible at launch ist deaktiviert
  • Fensters Release when closed ist auch nicht markiert

Mein Code unten dargestellt:

// 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__); 
} 

Meine Konsolenausgabe:

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:] 

Ich glaube, ich bin nur fehlt etwas Wichtiges. Jede Hilfe wäre willkommen.

+0

Vielleicht haben Sie Problem in dieser Frage beschrieben http://stackoverflow.com/questions/3539721/nswindowcontroller-loadwindow-loads-window-from-nib-but-showwindow-does-nothin – sergeyne

+0

Nein, es ist es nicht. – akashivskyy

Antwort

31

Versuchen Sie, authWindowController in eine Instanzvariable umzuwandeln. Derzeit ist es eine lokale Variable. Wenn die lokale Variable verschwindet, kann der Fenster-Controller freigegeben werden und das Fenster damit, so dass er nie angezeigt wird.

+1

Dies kann passieren, wenn Sie ARC verwenden, mehr Details in dieser Frage http://stackoverflow.com/questions/11677043/nswindowcontrollers-window-released-unmittelbar – sergeyne

+2

Ja, das hat den Trick. Vielen Dank! :) – akashivskyy

+0

Gerade lief in die gleiche Frage, danke für den Vorschlag – ribeto