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.
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