How to hide the initial window on start with OS X storyboards

前端 未结 4 1504
旧巷少年郎
旧巷少年郎 2021-02-07 23:00

I am creating an OS X status bar application, so I want the application to start hidden.

I have created a \"storyboard\" application, and the initial wi

4条回答
  •  醉梦人生
    2021-02-07 23:27

    Uncheck "Is Initial Controller", but then you need to set the storyboard and its associated NSWindowController manually.

    The precise way of doing that is shown in this answer, which I'll quote here:

    [...] in your AppDelegate, set up a property for the window controller:

    @property NSWindowController *myController;
    

    In your applicationDidFinishLaunching: method implementation, create a reference to the Storyboard. This way you get access your window controller from the storyboard. After that, the only thing left to do is to display the window by sending your window controller the showWindow: method.

    #import "AppDelegate.h"
    
    @interface AppDelegate ()
    @end
    
    @implementation AppDelegate
    
    @synthesize myController;
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
        // get a reference to the storyboard
        NSStoryboard *storyBoard = [NSStoryboard storyboardWithName:@"Main" bundle:nil]; 
        // instantiate your window controller 
        myController = [storyBoard instantiateControllerWithIdentifier:@"secondWindowController"];
        // show the window
        [myController showWindow:self];
    }
    
    @end
    

提交回复
热议问题