Reputation: 36896
I would like to launch a debug log window when my application opens. Here is how I planned to do this:
-(void)applicationDidFinishLaunching:(NSNotification *)notification
{
LogWindowController *lwc = [[LogWindowController alloc] initWithWindowNibName:@"LogWindow"];
[lwc showWindow:self];
[[lwc logWindow] orderFront:self];
}
The log window is created and operating, available in the Window menu for example. But it's not visible anywhere.
If I run the same code in response to a menu item, the log window shows as expected.
Why is this happening, and how can I open my log window visible on application launch?
Upvotes: 1
Views: 77
Reputation: 299345
There's nothing holding a strong reference to this window controller. At the end of this function, lwc
will be released, which will immediately close the window (before a drawing cycle has occurred, so you won't see a flash or anything).
You need to store lwc
in a strong
property so it isn't released until you want it to be.
Upvotes: 3