开发者

Call IBActions through different XIBs

开发者 https://www.devze.com 2023-01-11 19:50 出处:网络
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 su

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 but开发者_运维问答ton call an action from a different xib (if it is possible)?

Thank you in advance.

—Albé


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消