3

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?

0

2 Answers 2

10

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 :)

-1

It's working for me.

I added an IBOutlet to my AppDelegate.h

@property (nonatomic) IBOutlet NSWindow *window;

Then in your Interface Builder (MainMenu.xib for me) select App Delegate:

enter image description here

Your IBOutlet should be in the Connection inspector to the right:

enter image description here

Maybe the connection between your .xib and your AppDelegate is lost?

4
  • I've tried control clicking and dragging to my appdelegate.h file to create a reference outlet however it just won't do anything(normally that blue line would show up and id be able to create an iboutlet) I'm also using a storyboard not an .xib. This is basically a fresh cocoa app using a storyboard. I think I may just be confusing iOS basics with OSX but I feel like I should be able to just call self.window from appdelegate.m without having to do anything... May 28, 2015 at 13:28
  • Sorry, missed your Storyboard reference in your question. I haven't used Cocoa apps with storyboard so I might not be able to help you out here.
    – Jasper
    May 28, 2015 at 13:46
  • No worries, I think I found a way around my problem without needing to access the window through appdelegate! Thanks for the help :) May 28, 2015 at 14:07
  • did you find a solution? im stuck here Jul 31, 2015 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.