Error using NSWindowController

I just started a new Cocoa project after a long time ... And I don’t know why, but I always get an error when calling xib using NSWindowController. What I'm doing is very simple: I have a new project as a starting point, and then I don't want to call xib from Appdelegate, but from a subclass of NSWindowController. Then the output tells me that:

2014-11-12 09: 58: 18.519 SimpleTest [8554: 378690] ApplePersistence = NO

2014-11-12 09: 58: 18.671 SimpleTest [8554: 378690] Failed to connect (window) exit from (NSApplication) to (NSWindow): missing set or instance variable

Ok, how does it look in code? My Appdelegate is as follows:

#import "AppDelegate.h" #import "MainWindowController.h" @interface AppDelegate () @property (weak) IBOutlet NSWindow *window; @property (strong) MainWindowController *mainWindowController; @end @implementation AppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { _mainWindowController = [[MainWindowController alloc] initWithWindowNibName:@"MainMenu"]; [self.mainWindowController showWindow:self]; } @end 

Nothing special yet. MainWindowController as follows:

 #import "MainWindowController.h" @interface MainWindowController () @property (weak) IBOutlet NSWindow *window; @end @implementation MainWindowController - (id)initWithWindow:(NSWindow *)window { self = [super initWithWindow:window]; if (self != nil) { //do something } return self; } @end 

And again very simple ... Additiponally I have some changes in IB: File'Owner of MainMenu.xib becomes MainWindowController . Its "window" outlet is connected to the application window. The window delegate is connected to the file owner. Well it! But why am I getting this error? What am I doing wrong?

--- EDIT --- this shows the connections in IB

conncections

+5
source share

Source: https://habr.com/ru/post/1206713/


All Articles