> On Oct 10, 2016, at 3:36 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Oct 10, 2016, at 15:07 , Graham Cox <graham....@bigpond.com> wrote:
>> 
>> NSWindow, NSWindowController and NSView, NSViewController all inherit from 
>> NSResponder, which provide standard methods for dealing with keyUp and 
>> keyDown events.
> 
> I agree with everything you said, but a bit of caution is needed with 
> NSViewController subclasses, if the deployment target is earlier than 10.10.
> 
> Previously, view controllers were not in the responder chain (unless you 
> wrote code to put them there), and the “responder chain for events” section 
> of the Event Handling Guide doesn’t mention view controllers as any kind of 
> special case, as it does for window controllers.
> 
> I believe there are 4 possibilities:
> 
> 1. Subclass NSView to return true from ‘acceptsFirstResponder’. Otherwise the 
> events will go to the window.
> 
> 2. Subclass NSViewController to handle keyUp/Down. But it’s also necessary to 
> do #1, and if you want pre-10.10 compatibility, you should override 
> keyUp/Down in the view subclass instead.
> 
> 3. Subclass NSWindow to handle keyUp/Down.
> 
> 4. Subclass NSWindowController to handle keyUp/Down.
> 
> Of these, #4 is the easiest and least treacherous, but I get the impression 
> Eric wants to centralize his business logic in the view controller and pretty 
> much ignore the window controller (which is a fairly reasonable attitude in 
> these storyboard days). In that case, he can have the window controller call 
> view controller methods, preferably *not* keyUp/Down overrides, but it would 
> make more sense to encapsulate everything in the view/view controller 
> combination, which means #1 and probably #2, depending on deployment.
> 
> What I find interesting about this problem is that there’s a really easy 
> solution, except that it’s easy only in the it’s-a-very-*small*-can-of-worms 
> sense. That’s why we love old-school Cocoa.

From this list #1 seems to me to be the most standard paradigm for handling 
events. If you have a view controller you have a view already, so making the 
root view of the controller handle events via 'acceptsFirstResponder' and using 
'becomeFirstResponder' seems like the easiest and most standard way to go. #2 
could also work, as NSViewController also derives from NSResponder, so, you 
could have the controller handle all key events as well.
All the other options have various levels of hackiness that are probably more 
trouble than they're worth, IMHO.

Doug Hill
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to