Cocoa NSPopupButton问题

时间:2011-01-14 08:05:22

标签: objective-c cocoa macos xib nsviewcontroller

在我的Cocoa应用程序中,在一个视图中,我通过“接口”构建器添加了一个NSPopupButton,并将其与源文件相关联, 现在在Code中,我正在动态创建Menu并使用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];

当我运行应用程序时,最初按钮已启用,但是当我单击箭头时,包括菜单和按钮被禁用

请告诉我我做错了什么。

1 个答案:

答案 0 :(得分:0)

您需要启用NSPopUpButton的操作。目标是可选的(nil表示第一响应者)。

您不需要为菜单项设置目标/操作,因为弹出窗口可以告诉您在针对其目标调用其操作时选择了哪个项目。

相关问题