【发布时间】:2011-01-14 08:05:22
【问题描述】:
在我的 Cocoa 应用程序中,在一个视图中,我通过 Interface builder 添加了一个 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];
当我运行应用程序时,最初按钮是启用的,但是当我单击箭头时,包括菜单和按钮被禁用
请告诉我我做错了什么。
【问题讨论】:
-
它看起来不错,尽管您在弹出按钮上调用
setTarget:而不设置操作。由于您要为每个菜单项添加操作,因此只需不指定按钮本身的目标/操作即可。 -
嗨,我也试过了,没有运气:(
标签: objective-c cocoa macos xib nsviewcontroller