On Oct 3, 2015, at 07:42 , Jonathan Mitchell <[email protected]> wrote:
> 
> The responder chain is, as you know, very flexible.

I’m not accusing you of mistreating the responder chain, I’m accusing you of 
mistreating event handling. :)

Event handling is based on the idea of hierarchical containment, so that a view 
controller is expected to handle only actions from its own view’s 
sub-hierarchy. You’re trying to route actions from elsewhere into the view 
controller “container”. (iOS already has this concept of view controller 
containment, that parallels the view containment hierarchy.)

I suggest you consider breaking your view controllers apart into two objects. 
One, a “view responder” would be a NSResponder subclass that you insert into 
the responder chain just below the window controller. The other, an actual 
NSViewController subclass, would be inserted into the responder chain wherever 
the frameworks want, or possibly not at all pre-10.10.

Ideally, all of the business logic would be moved from its current home in the 
view controller to the view responder, including the action messages. All 
that’d be left in the view controller would be the outlets (if any), and the 
viewDidLoad logic necessary to prepare the view itself (and also to create the 
view responder, and insert it in the responder chain). Alternatively, you could 
keep all the local-to-view logic in the view controller, and put only the 
trans-view logic in the view responder, but this may get a bit messy if both 
share the same custom data structures.

This shouldn’t involve much change to existing code. Each object in the pair 
would have a reference to the other. Except for the responder chain setup, the 
main difference in code would be that your view responder would reference 
outlets as self.viewController.myOutlet, instead of self.myOutlet. If you have 
view controller bindings in the NIBs, you can change them to bind through to 
the view responder, or (if there are too many to change) define derived 
properties in the view controller that mirror the real properties in the view 
responder.

_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to