我想要一个动态子菜单。现在我尝试了这种方式:
@interface AppController()
@property(strong) Accounts * accView;
@property (weak) IBOutlet NSMenuItem *serverMenu;
@end
@implementation AppController
-(void)awakeFromNib {
_accView = [[Accounts alloc] initWithNibName:@"Accounts" bundle:nil];
[self.viewk addSubview:[_accView view]];
[[_accView view] setFrame:self.viewk.bounds];
NSMenuItem * testItem = [[NSMenuItem alloc] initWithTitle:@"Test" action:@selector(test:) keyEquivalent:@""];
[[_serverMenu submenu] addItem:testItem];
}
- (void)test:(id)test {
}
然后它被添加但我无法点击它。就像这样:
如何启用它?
答案 0 :(得分:1)
您还需要为NSMenuItem分配目标,例如
[testItem setTarget:self];