gpt4 book ai didi

macos - NSPopUpButton 的 SetAction 正在禁用我的 popUpButton

转载 作者:行者123 更新时间:2023-12-03 16:06:56 25 4
gpt4 key购买 nike

我使用以下代码以编程方式创建了 NSPopUpButton

[myPopUpButton insertItemWithTitle:@"--Select one--" atIndex:0];
[myPopUpButton addItemsWithTitles:[NSArray arrayWithObjects:@"1.One",@"Two",@"Three", nil]];

[myPopUpButton sizeToFit];
[myPopUpButton setAction:@selector(popUpAction:)];
[fullBrowserView addSubview: myPopUpButton];

//PopUp Action
-(void)popUpAction:(id)sender
{
NSLog(@"popUpAction");
}

当我单击 popUpButton 时,popUpButton 的菜单项被禁用。当我使用 InterfaceBuilder 时,它与 IBAction 一起工作正常。

为什么这个 setAction 不适用于 NSPopUpButton?

最佳答案

看起来您没有设置要发送消息的目标对象。因此,在代码中添加:

[myPopUpButton setTarget:self];

假设 popUpAction: 方法位于同一个类中。

当您使用 Interface Builder 时,它将选择器操作连接到目标。

来自此调用的文档:

- (void)setTarget:(id)anObject

If anObject is nil but the control still has a valid action message assigned, the application follows the responder chain looking for an object that can respond to the message.

在您的例子中,没有对象响应该消息。

关于macos - NSPopUpButton 的 SetAction 正在禁用我的 popUpButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9600523/

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