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?
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 :)
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:
Your IBOutlet should be in the Connection inspector
to the right:
Maybe the connection between your .xib and your AppDelegate is lost?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.