Hi Steve,

There are lots of ways to debug this. Try listening for NSMenuWillSendActionNotification to see if the menu is actually sending an action. Override [NSApp sendAction:to:from:] to see what actions are sent, and to which object. Override [NSMenu performActionForItemAtIndex:] to see what your menu state is when the item is selected.

If you aren't able to figure out what's going on, you can write up a test case that exhibits the problem and put it on the web. I or someone else will take a look.

To set the target for the menu item explicitly, use setTarget: on the result of the addItemWithTitle:... method, which returns the new item.

Hope this helps,
-Peter


On Aug 25, 2008, at 12:12 PM, Steve Cronin wrote:

Peter;

On the responder chain: I'm not sure I precisely understand your question - where are you expecting me to call this? If I call it at the time the submenu is being constructed I get: appDelegate Since I can't get any response to selecting the item itself, I can't tell you what I would get if I called it when the item is invoked =;-(

If you use the NSMenu method -addItemWithTitle:(NSString *) action: (SEL) keyEquivalent:(NSString *) what is the recommended way to set the target for the menuItem added by this method? Why doesn't the method allow you to set the target as well as the selector, in one fell swoop?

How can I effect the responder chain, if I am just adding a submenu to menuitem on the menubar?

The REAL maddening thing here is that I have another similar data driven submenu that uses the same mechanism and it works fine. I've been over and over the IB settings for the darn things and I can't find any differences! Same point in time the submenu are being constructed and attached; and same exact objects involved in the selector....

Thanks for any additional data.
Steve



On Aug 25, 2008, at 1:20 PM, Peter Ammon wrote:


On Aug 25, 2008, at 12:53 AM, Steve Cronin wrote:

Folks;

I'm building a data driven submenu programmatically.
The submenu appears correctly in the UI with the correct titles but nothing happens when these items are selected.

[...]

I set a breakpoint at customAction:  it NEVER gets called.
(Yes I have spelled it correctly [- (void) customAction:(id)sender;]

This is on the mainMenu in the main XIB file. There is an outlet from appDelegate for mainMenu, this is set.
The menu itself has the appDelegate set as its' delegate.
The selector method is o method in the appDelegate object.
There are no selector bindings set.
(Note: there are enabled bindings set which are working correctly)

The most likely problem is that the object implementing the method is not in the responder chain. What object do you get if you call [NSApp targetForAction:@selector(customAction:)]?



I'm just stumped!  I probably could use some sleep...
Also how do you show some useful data from a SEL value in NSLog? ie print [NSMenuItem action]?

For debugging purposes, the easiest thing to do is to cast it to a char*, e.g.:

gdb)  p (char *)[someMenuItem action]

For your actual code, you should use the NSStringFromSelector() function, as the char* nature of selectors is not guaranteed.

-Peter



_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to