Re: How do I enable a menu item?
Re: How do I enable a menu item?
- Subject: Re: How do I enable a menu item?
- From: Greg Titus <email@hidden>
- Date: Sat, 30 Mar 2002 19:38:00 -0800
Actually, you don't _have_ to implement -validateMenuItem: at all. If
you don't implement it, the menu item will always be enabled if it has a
valid target. (A target which implements its action selector.) It will
disable itself if it has no target that implements its action.
So Tony's problem is either (1) the menu item target isn't actually
connected, (2) the application controller doesn't actually implement the
action selector, (3) the menu that the item is in has 'autoenable items'
turned off (unlikely, but possible, you can select the menu in IB and
check the attributes inspector), or (4) he is already implementing
-validateMenuItem: and it is returning NO.
Hope this helps,
--Greg
On Saturday, March 30, 2002, at 05:56 PM, Alex Rice wrote:
On Saturday, March 30, 2002, at 06:34 PM, Tony Gray wrote:
Hi,
I'm still learning Cocoa.
Still! Phshaaaw-- there are only approx 300 classes ;-)
I've just added my own menu item my application's
application menu, and (when this is selected) I want this to call a
method
in my application's controller. I can wire this up OK, but the
problem is,
this new menu is disabled, both when I test the interface in IB, and
when I
compile and run my app.
Do I have to programmatically enable my own custom menu items, or
have I
missed something obvious (or otherwise!) in IB?
The default is for dynamic enabling of menu items. This gives you a lot
of control, but also you have to do a little extra work up front to
enable them in them in first place: Implement this method in the class
that's receiving the action of the menu item in question:
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem
{
if ([item action] == @selector(doit:))
return YES;
return NO;
}
Alex Rice <email@hidden>
Mindlube Software
http://www.mindlube.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.