Re: Setting the action for a menu item
Re: Setting the action for a menu item
- Subject: Re: Setting the action for a menu item
- From: Nick Zitzmann <email@hidden>
- Date: Mon, 3 Feb 2003 20:07:14 -0800
On Monday, February 3, 2003, at 03:19 PM, Jeffrey Mattox wrote:
1. It works fine (the menu and the items are there), but I don't know
how to connect the "action:" to another routine in my Cocoa file. How
do I do that?
If you have an action method defined like this:
- (IBAction)genericAction:(id)sender;
Then you would do this:
theMenuItem = [theMenu insertItemWithTitle:@"Item"
action:@selector(genericAction:) keyEquivalent:@""
atIndex:i];
The action method can either "return" IBAction or void, depending on
whether you use the action from objects in the nib or not.
2. The menu items will use the same handler, I just need to pass a
different value for each item. I assume I use the "setTarget:" and/or
"setTag:" methods -- is that correct? If so, does the tag show up as
a parameter on the action handler?
If I'm understanding you correctly, you need to give the menu item a
"represented object". You can do this by setting up a custom NSMenuItem
and inserting that into your NSMenu. Then, in the action handling the
menu item, you can call [sender representedObject] to draw out the
object associated with the menu item. See the NSMenuItem documentation
for details.
Nick Zitzmann
AIM/iChat: dragonsdontsleep
Check out my software page:
http://dreamless.home.attbi.com/
#include <stdsignature.h>
_______________________________________________
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.