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:
And synthesized it in your implementation file:
Then you could set up like this:
Now your window won’t disappear. The window controller will be released when the application closes.