gpt4 book ai didi

objective-c - 子菜单项不可点击

转载 作者:行者123 更新时间:2023-12-03 17:51:01 24 4
gpt4 key购买 nike

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

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

}

然后它就被添加了,但我无法点击它。是这样的:

enter image description here

如何启用它?

最佳答案

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

[testItem setTarget:self];

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com