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