Re: NSWindowControllers and NSWindow
Re: NSWindowControllers and NSWindow
- Subject: Re: NSWindowControllers and NSWindow
- From: Dave <email@hidden>
- Date: Mon, 16 Feb 2015 19:58:10 +0000
> On 16 Feb 2015, at 18:39, Bill Cheeseman <email@hidden> wrote:
>
> Although I follow Mike Ash's advice, I have separate MainMenu.xib and MainWindow.xib files instead of a single window.xib file. My MainMenu.xib contains the application's menu bar but no window. MainMenu.xib is owned by NSApplication, and NSApplication's delegate outlet is connected to my AppDelegate object, which is included in MainMenu.xib. MainMenu.xib is loaded, its included AppDelegate object is instantiated, and its applicationDidFinishLaunching delegate method is called, all automatically at launch due to the way the standard Main file works. My AppDelegate class implements NSApplicationDelegate protocol methods as needed, and it handles a few other things that are of application-wide relevance. It tends to be fairly small and simple.
Same as I have.
> Because MainMenu.xib contains no window, the application has a menu bar but nothing else up to the point where AppDelegate's applicationDidFinishLaunching delegate method is called. The window is contained in MainWindow.xib, which is owned by my MainWindowController class. The applicationDidFinishLaunching delegate method in AppDelegate loads MainWindow.xib by calling initWithWindowNibName (I don't buy Mike's advice to declare a simple init method), and at this point the application has both a menu bar and a window. The window's Visible At Launch behavior is set in MainWindow.xib, so the window appears when the application is launched and MainWindow.xib is loaded, without having to call showWindow (or you can just call showWindow). In AppDelegate's applicationDidFinishLaunching delegate method, I set the AppDelegate's mainWindowController and window instance variables to the new window controller and to its new window, so that the AppDelegate can refer to them as needed.
This is slightly different that I have an Outlet defined in the MainMenu.xib file which is set to LTWMainWindowController and I do use a simple init method inside of LTWMainWindowController that calls initWithWindowNibName with @“LTWMainWindow”.
>
> The MainWindowController implements the outlets and action methods and any delegate methods for the window and all or most of its buttons and other UI elements. It can refer to the menu bar and other things in the AppDelegate as needed by calling NSApp.delegate. In turn, AppDelegate can refer to the window, its UI elements, and the window controller as needed by using AppDelegte's instance variables for them.
>
Thanks again, I think I’ve got it now!
Cheers
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden