Re: NSWindowControllers and NSWindow
Re: NSWindowControllers and NSWindow
- Subject: Re: NSWindowControllers and NSWindow
- From: Steve Mills <email@hidden>
- Date: Mon, 16 Feb 2015 10:51:43 -0600
On Feb 16, 2015, at 09:24:36, Dave <email@hidden> wrote:
>
> Thanks for this, it seems to be saying there is no need for a separate Window Subclass and that the Window Controller Subclass contains all the code needed to drive the window. I’m a bit confused of when to use an NSWindow and when to use and NSWindowController?
>
> The way I had thought to do this was to have:
>
> LTWMainWindowController.h, .m and .xib files and LTWMainWindow.h, .m and .xib files.
>
> Is this the best approach? Or it is better to put the code in the LTWMainWindow.h, .m and .xib files directly into LTWMainWindowController?
>
> Or instead of using NSWindowController and NSWindow should I be using NSWindowController and NSViewController?
>
> I’m really confused how to lay this out and want to start off on the right foot.
NSWindow rarely needs to be subclassed. The controller is where all the custom action usually happens. Think of the window as the graphical representation of the pair, but the controller is what controls how the window works, and it's where you would put IBAction methods that the various controls in the window will call when they're acted upon. E.g. a button named "Karate Chop" would be connected to "-(IBAction) karateChop:(id)sender" in the controller, and that's where you would put the code to commence a karate chop.
Now think of your different windows. Assumedly, they all have different controls and views, and take care of different aspects of the app, like you said. Therefore, good program design would call for a different specialized controller subclass for each window. *if* needed. I say "if needed" because, depending on the simplicity of a window, it could be done entirely through Cocoa Bindings or other methods, but usually not.
Look at some sample apps on Apple's developer site. Like Sketch maybe.
--
Steve Mills
Drummer, Mac geek
_______________________________________________
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