假设 button1 是一个 NSPopUpButton 假设附加到 button1 的菜单被显示并被跟踪。
[[button1 cell] dismissPopUp] ---dismissPopUp 无法识别。
为什么dismissPopUp方法无法识别?
谢谢
假设 button1 是一个 NSPopUpButton 假设附加到 button1 的菜单被显示并被跟踪。
[[button1 cell] dismissPopUp] ---dismissPopUp 无法识别。
为什么dismissPopUp方法无法识别?
谢谢
因为 NSCell 不响应dismissPopUp
消息。
如果您在运行时将此视为异常,请确保button1
确实是一个弹出按钮——也就是说,确保您将该插座连接到 IB 中的正确对象,或者如果您在此处分配了正确的对象在代码中创建它。在后一种情况下,使用调试器检查变量。
如果这只是您从编译器得到的警告,那可能是因为它cell
是 NSControl(NSPopUpButton 的超类)的一个方法,并且被键入为返回一个 NSCell。编译器无法知道此特定控件将返回 NSPopUpButtonCell。解决方案是将cell
消息的结果分配给类型为 的变量NSPopUpButtonCell *
,然后将dismissPopUp
消息发送到该变量中的对象:
NSPopUpButtonCell *cell1 = [button1 cell];
[cell1 dismissPopUp];
如果您仍然收到警告,则需要在[button1 cell]
表达式前面添加显式转换。