On Jan 6, 2013, at 8:06 AM, Keary Suska <cocoa-...@esoteritech.com> wrote:

> Just to be explicit, the custom NSView must also itself be in the responder 
> chain--i.e. the first responder must the the view or one of its descendants. 
> Also, you need to make sure that no other responder in the chain *below* the 
> controller implements -validateMenu/UserInterfaceItem: and returns NO for the 
> menu actions.

To expand on this -- at the time when you click a button or select a menu item, 
it's possible for something *outside* the view to be the window's first 
responder. It's easy to assume that when the button is inside your view, the 
responder-chain search will start with that button, and thus eventually find 
your view controller. But that is not so; for example, imagine a text field 
outside your view (but in the same window) that has focus. That text field will 
be first responder. Also, consider that a menu item doesn't live in your 
window; it searches for a responder to the action based on whatever the current 
first responder is.

To fix this you can move your view controller higher in the responder chain -- 
either after the window or after the window controller, so that regardless of 
what the first responder is, it will be found in the window's responder chain 
and thus will respond to the action.

> Other debugging aids are to trace through -setViewController: to make sure 
> everything is wiring up correctly. I might also implement or put a breakpoint 
> in the validate method in an object that I know is in the chain "naturally", 
> such as the window controller. I would also double check the nextResponder 
> value after-the-fact (a good place would be in the validate method I 
> mentioned), to make sure it isn't being changed. I doubt this is the case but 
> it doesn't hurt to check.

Yup, and you could also double-check the nib to make sure the action is 
connected to First Responder. If the button is in the nib and the view 
controller is File's Owner, you could connect directly to File's Owner and 
avoid searching the responder chain at all. Menu items would still have to 
connect to First Responder though.

If you're making the connections with code rather than IB, make sure nil is the 
target for the action.

--Andy


_______________________________________________

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