NSWindowController showWindow: flashes the window

前端 未结 1 432
无人共我
无人共我 2021-01-04 11:16

So I\'m trying to open a new NSWindow like so:

NSWindowController *winCon = [[NSWindowController alloc] initWithWindowNibName:@\"NewWindow\"];
[winCon showWi         


        
相关标签:
1条回答
  • 2021-01-04 12:05

    First, the name of the initializer isn't -initWithNibName:, but -initWithWindowNibName:.

    Second, and this is true if you're using ARC, your window goes foom because you don't have a strong reference for your instance of NSWindowController. When the method ends, so does your reference.

    If, say, you were to do this instead in your application delegate interface:

    @property(strong) NSWindowController *winCon;
    

    And synthesized it in your implementation file:

    @synthesize winCon;
    

    Then you could set up like this:

    self.winCon = [[NSWindowController alloc] initWithWindowNibName:@"NewWindow"];
    [self.winCon showWindow:self];
    

    Now your window won't disappear. The window controller will be released when the application closes.

    0 讨论(0)
提交回复
热议问题