Re: Re: First Responder and menus
Re: Re: First Responder and menus
- Subject: Re: Re: First Responder and menus
- From: "Michael Ash" <email@hidden>
- Date: Wed, 5 Jul 2006 02:01:12 -0400
On 7/4/06, Matt Neuburg <email@hidden> wrote:
On Tue, 4 Jul 2006 08:52:12 -0400, "Alan Smith" <email@hidden>
said:
>I'm trying to hook a menu item in one nib to an action of a controller
>in another nib. I spent this morning reading about First Responder and
>have thoroughly searched the internet. I found lots of articles but
>they all say the same thing: Add an action in the First Responder in
>the nib with the menu item and add an action to the controller. Well,
>I've done that and the menu item remains grayed out. I then tried
>making my controller a NSWindowController, that didn't help either.
Here's a really great trick for these situations. Simply implement
validateMenuItem: in the same class where you hope to receive the action
message, and add some logging so you know whether it's being called. Now run
your app and attempt to choose your menu item. If validateMenuItem: isn't
called, your instance is not in the responder chain and you need to review
your understanding of the responder chain. m.
validateMenuItem: won't get called unless the system has already
determined that your object responds to the action. So it will catch
problems like hooking up the action correctly, but the menu item is
disabled for some other reason, but it will not catch problems such as
a mismatch between the name of the action in the nib and the name of
the method in the source code. For a more complete listing of what's
flying around the system, implement respondsToSelector:. This can
catch non-responder-chain things as well, and still won't trigger if
something ahead of you in the chain responds to the action too, but it
catches more cases overall.
Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden