Skip navigation.
 
mlbuilding a menu at run-time and enabling the items
FROM : John Spicer
DATE : Fri Nov 19 19:02:33 2004

I'm building a menu at run-time. I add items to the menu, and each one
is given a selector as shown.

The menu items won't enable. I'm not setting a target for the menu
item, only a selector. Is this possibly the problem?

The code I'm using is shown below:

   NSMenu *theMenuBar = [NSApp mainMenu];
   NSMenuItem *theView = [theMenuBar itemWithTitle:@"MyMenu"];
   NSMenu *myMenu = [theView submenu];

   for (int i = 0; i< [inData count]; i++)
   {
       NSDictionary *d = [inData objectAtIndex:i];
       NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:[d
objectForKey:@"Name"] action:@selector(somethingWasChoosen:)
keyEquivalent:@""];
       [item setTag:[[d objectForKey:@"Code"] intValue]];
       [myMenu addItem:item];
   }


and later somethingWasChoosen is defined as:

- (IBAction) somethingWasChoosen:(id)sender
{
}

Related mailsAuthorDate
mlbuilding a menu at run-time and enabling the items John Spicer Nov 19, 19:02
mlRe: building a menu at run-time and enabling the items Jesus De Meyer Nov 19, 19:06
mlRe: building a menu at run-time and enabling the items John Spicer Nov 19, 19:52
mlRe: building a menu at run-time and enabling the items Glenn Andreas Nov 19, 20:07