通过不同的 XIB 调用 IBAction
我将 NSMenuItem 放入基于文档的应用程序的 MainMenu.xib 中。我可以设置一个关键当量。对于 Interface Builder 中的此项,无论如何该项都无法调用 NSDocument 子类实例(存在于 MyDocument.xib 中)中定义的 IBAction。我怎样才能让该按钮调用来自不同 xib 的操作(如果可能的话)?
先感谢您。
——阿尔贝
I put a NSMenuItem in the MainMenu.xib of a document-based application. I can set a key equiv. for this item in Interface Builder, anyway that item can't call an IBAction defined in the NSDocument subclass instance (which exists in MyDocument.xib). How can I make that button call an action from a different xib (if it is possible)?
Thank you in advance.
—Albé
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将您的菜单项连接到第一响应者。当文档窗口处于活动状态时,其文档位于响应程序链中,以便它可以响应您分配给菜单项的操作。
请注意,您只能在类的标头中声明您的操作之后才能将其连接到您的操作。该类是否在 MainMenu 笔尖中实例化并不重要;只要该操作在标头中声明,并且标头和 MainMenu nib 都在同一个项目中,IB 就会知道您所做的事情是有效的。如果您尚未声明该操作,则该操作不会显示在 IB 的可能操作列表中。
Connect your menu item to the First Responder. When a document window is active, its document is in the responder chain so that it can respond to actions like the one you assigned to your menu item.
Note that you can only hook it up to your action after you've declared your action in a class's header. It doesn't matter whether that class is instantiated in the MainMenu nib or not; as long as the action is declared in the header and the header and MainMenu nib are both in the same project, IB will know that what you're doing is valid. If you haven't declared the action yet, it won't show up in IB's list of possible actions.