So I'm trying to open a new NSWindow like so:
NSWindowController *winCon = [[NSWindowController alloc] initWithWindowNibName:@"NewWindow"];
[winCon showWindow:self];
When I do this, the new window flashes on the screen, as in it appears and then quickly disappears. I know that I have my window correctly referenced in IB and everything. It's like it wants to show the window, but then it gets deallocated or something weird almost immediately. Any help will be appreciated.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With