我想要一个动态子菜单。现在我尝试这种方式:

@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 {

}


然后添加了它,但我无法单击它。就像这样:



如何启用它?

最佳答案

您还需要为NSMenuItem分配一个目标,例如

[testItem setTarget:self];

关于objective-c - 子菜单项不可点击,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26405123/

10-12 05:39