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

macos – NSPopUpButton的SetAction正在禁用我的popUpButton,第1张

概述我已使用以下代码以编程方式创建了NSPopUpButton [myPopUpButton insertItemWithTitle:@"--Select one--" atIndex:0];[myPopUpButton addItemsWithTitles:[NSArray arrayWithObjects:@"1.One",@"Two",@"Three", nil]];[myPopUpBut 我已使用以下代码以编程方式创建了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全部内容,希望文章能够帮你解决macos – NSPopUpButton的SetAction正在禁用我的popUpButton所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1021887.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存