• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Menu item validation problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Menu item validation problem


  • Subject: Re: Menu item validation problem
  • From: David Remahl <email@hidden>
  • Date: Fri, 18 Jul 2003 09:49:23 +0200

Just in case anyone was looking at this, I just wanted to tell you I found the problem. A stupid one, at that. I made a spelling mistake in the action method name in my controller, so it didn't match the action of the menu items. Because of that, the menu validation code in my controller was never called. I can't believe how I overlooked it for so long!

/ Rgds, David

On onsdag 16 juli 2003, at 08.32AM, David Remahl wrote:

Hi.

I have a problem with autoenabling of a menuitems in a programmatically created menu hierarchy. The menu is created in code, as opposed to in Interface Builder. It contains a number of items with submenus, and each submenu contains a number of items. Each of these items have a nil target and an action. The top level menu has been sent setAutoenablesItems:YES, and so have each of the sub menus. The top level menu is set as the sub menu of a top level menu item (an item attached to the horizontal menu bar). The top level menu is a subclass of NSMenu, but overrides none of the methods in NSMenu.

The application is document based, and has one window per document. The NSDocument is set to be the window's delegate. In the NSDocument subclass, I implement the method that is the action of each leaf menu item. The NSDocument subclass does get validation messages for other items with action = nil (first responder), but _not_ for the any of the items in the programmatically created menu.

All the leaf items in the programmatically created menu stay disabled. Even if I implement their action in the app delegate, they stay disabled.

What could I possibly have missed!?

Some example code (non-authentic, actually written in Mail...):

@implementation DRMyMenu

- (id)initWithTitle:(NSString *)string
{
if( self = [super initWithTitle:string] )
{
int i, j;

for( i = 0; i < 5; i++ )
{
NSMenu *subMenu = [[[NSMenu alloc] initWithTitle:[NSString stringWithFormat:@"%i",i]] autorelease];
NSMenuItem *subMenuOwner;

for( j = 0; j < 5; j++ )
{
NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%i", j]
action:@selector(myAction:) keyEquivalent:@""];
[subMenu addItem:menuItem];
[menuItem release];
}

subMenuOwner = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"%i", i]
action:NULL keyEquivalent:@""];
[subMenuOwner setSubmenu:subMenu];

[self addItem:subMenuOwner];
[subMenuOwner release];
}
}

return self;
}

@end

@implementation AppController

- (IBAction)myAction:(id)sender
{

}

- (void)awakeFromNib
{
[topMenuItem setSubmenu:[[[DRMyMenu alloc] initWithTitle:@"TopMenu] autorelease]];
}

@end

/ Thanks, David Remahl
_______________________________________________
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.

References: 
 >Menu item validation problem (From: David Remahl <email@hidden>)

  • Prev by Date: Pref Panes and IAC
  • Next by Date: _NSDrawWindowBackgroundRegion bombs
  • Previous by thread: Menu item validation problem
  • Next by thread: Re: System serial number -> Apple please implement
  • Index(es):
    • Date
    • Thread