0
votes

In my Cocoa Application, In One view i added a NSPopupButton via Interface builder and linked that accordingly with the source file, Now in the Code, i am creating Menu dynamically and adding menu with the NSPopupbutton, This is i have done it in WindowDidLoad Please refer the code below

 NSString *pThemeName;
 for(;index<count;index++)
 {
  pThemeName = [pThemeArray objectAtIndex:index];

  /* If its valid them go ahead and add that into the 
     list 

   */
  if([CommFileManager IsValidThemeName:pThemeName]){
   menuItem = [[NSMenuItem alloc] initWithTitle:pThemeName action:@selector(selectThemeName) keyEquivalent:@""];
   [menuItem setTarget:self];
   [pPopUpmenu addItem:menuItem];
   [menuItem setTag:index];
   [menuItem release];
  }
 }
 [pPopupButton setTarget:self];
 [pPopupButton setMenu:pPopUpmenu];
 [pPopupButton selectItem:[pPopUpmenu itemAtIndex:5]];
 [pPopUpmenu release];

When i run the application, then initially the button is Enabled, but when i click the arrow , including Menu and button gets disabled

Please tell me what i am doing wrong.

1
It looks fine to me, although you call setTarget: on the popup button without setting an action. Since you're adding actions to each of the menu items, just leave the target/action of the button itself unspecified. - d11wtq
HI i tried without that also, no luck :( - Amitg2k12

1 Answers

0
votes

You need an action for the NSPopUpButton to be enabled. Target is what's optional (as nil means first responder).

You do not need to set a target/action for the menu items, since the popup can tell you which item was selected when it calls its action against its target.