Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference outlet to main NSWindow in AppDelegate (OSX)

When you create a new project, I seem to remember you being able to access the basic blank window it creates in the storyboard using self.window in the AppDelegate methods.

I can't seem to set a reference outlet to the AppDelegate.h file via the storyboard either. Am I just hallucinating or is there no way to access the window/controller from AppDelegate?

Am I mixing up iOS and OSX practices?

like image 652
Julian Hunt Avatar asked Dec 04 '25 23:12

Julian Hunt


1 Answers

Using storyboards, it seems impossible to connect the WindowController to AppDelegate. I used the following to get a reference to the main window:

AppDelegate.h

@property (weak) NSWindow* window;

AppDelegate.m

    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
            _window = [[[NSApplication sharedApplication] windows] firstObject];
    }

See this question for swift solution. Hope this helps :)

like image 50
scx Avatar answered Dec 06 '25 13:12

scx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!