On Jan 6, 2013, at 16:53, Arved von Brasch <co...@atgo.org> wrote:

> I first noticed a problem when I couldn't get a NSMenuItem to validate, but 
> it seems to also be a problem with buttons.

Don't get side-tracked by looking at button actions. Validation works 
differently, and since buttons are not normally first responder, the responder 
chain starting from any given button doesn't tell you anything about "first 
responder" and its chain.

To debug the menu item validation, first *remove* the 'validateMenuItem:' code 
from your view controller. Then, look and see if the relevant menu item is 
enabled or disabled.

Assuming the menu item is set to target "first responder" (i.e. its target is 
nil), and it's set to auto-enable, then it's enabled if and only if something 
in the responder chain, starting from the actual first responder, implements 
your action method.

Therefore, assuming your view controller implements the action method, if the 
menu item is disabled, your view controller isn't in the responder chain 
starting from the first responder. For example, the window itself might be 
first responder, in which case the menu won't be enabled.

Note that this is an inherent issue when using view controllers to control 
parts of a window: it can't just serve as a sub-controller for the window as a 
whole, though that's often what you want it to do. Putting that a different 
way, the view controller doesn't get control just because its view is in the 
window. It gets control only when its view or a subview of its view is first 
responder.

You haven't given us enough information to work out whether the view controller 
is being "abused" in the manner I just described.

I guess, though I've never tried it, that if you arrange to insert the view 
controller into the responder chain just *below* (i.e. before) the window 
controller, then things should work as you perhaps are expecting. The danger 
with doing this, though, is that messing with the responder chain that far up 
*might* fall foul of other classes' assumptions about the chain structure. I 
dunno, it might be safe enough, but this is usually the point at which I get 
nervous and go looking for a different approach.

(BTW, once you've got the auto menu enabling working without a validation 
method, then add the validation method -- preferable validateUserInterfaceItem 
rather than validateMenuItem.)

_______________________________________________

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