在我的Cocoa应用程序中,在一个视图中,我通过接口构建器添加了一个NSPopupbutton,并相应地将其链接到源文件,现在在代码中,我正在动态创建菜单,并使用NSPopupButton添加菜单,这是我在WindowDidLoad中完成的请参阅下面的代码
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];当我运行应用程序时,最初该按钮是启用的,但当我单击箭头时,包括菜单和按钮在内的按钮将被禁用
请告诉我我哪里做错了。
发布于 2011-01-14 19:20:00
您需要一个操作才能启用NSPopUpButton。目标是可选的(因为nil表示第一响应者)。
您不需要为菜单项设置目标/操作,因为弹出窗口可以告诉您在针对其目标调用其操作时选择了哪一项。
https://stackoverflow.com/questions/4689052
复制相似问题