In this answer is said it is possible to have a custom NSWindowController by removing the window from MainMenu.xib and instantiating the window controller 'manually' from applicationDidFinishLaunching:
. But it also says:
To stop the default window from showing I just delete it. There's probably a better way but I don't know that.
Is there a better way? What is that better way, should it exist? Is it considered 'normal' practice to get your own window controller?
To do this, you would usually subclass NSWindowController and change the File's Owner class to your WindowController subclass in the nib.
EDIT:
If you aren't doing a document-based app, and just want an NSWindowController of your own to do on-demand loading of Nibs (completely reasonable), then you'd delete the window from your nib and instantiate an NSWindowController
subclass programmatically, using it explicitly to do your window loading...
@implementation MyApplicationDelegate {
MyWindowControllerSubclass *windowController;
}
-(void)applicationDidFinishLaunching:(NSNotification *)notification {
windowController = [[MyWindowControllerSubclass alloc] initWithWindowNibName:@"MyWindowNib"];
[windowController showWindow:nil];
[windowController.window makeKeyAndOrderFront:nil];
}
I was running into the same issue and I want to show you my own solution.
self.customWindowController = [[AccountWindowController alloc] initWithWindowNibName:@"CustomWindow"];
and show the Window [self.customWindowController showWindow:nil]
in - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
Here is an example project https://www.dropbox.com/s/ft3t7w72806tnoe/CustomWindowController.zip
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