简体   繁体   English

如何将IBAction和菜单项连接到First Responder?

[英]How to connect IBAction and menu item to First Responder?

In Xcode storyboard I am trying to connect IBAction from ViewController to menu item in application scene (the menu bar). 在Xcode storyboard中,我试图将ViewAtroller中的IBAction连接到应用程序场景(菜单栏)中的菜单项。

I found a solution telling that I should connect the menu item to First Responder. 我找到了一个解决方案,告诉我应该将菜单项连接到First Responder。 Then the First Responder to IBAction, since First Responder presents on every scenes. 然后是IBAction的第一响应者,因为First Responder呈现在每个场景上。 So, the First Responder can receive action from menu bar first as nil then chain it to IBAction. 因此,First Responder可以首先从菜单栏接收操作,然后将其链接到IBAction。

I however cannot figure out how to connect menu item to First Responder and First Responder to IBAction. 然而,我无法弄清楚如何将菜单项连接到IBAction的First Responder和First Responder。 When I ctrl+dragged menu item to First Responder, it shows only preset actions. 当我按住Ctrl +拖动菜单项到First Responder时,它只显示预设动作。 And I cannot ctrl+drag ViewController to First Responder on viewController scene at all. 而且我无法在viewController场景上按Ctrl +拖动ViewController到First Responder。

How do I connect IBAction and menu item to First Responder? 如何将IBAction和菜单项连接到First Responder?

When you create an IBAction either by dragging from IB or writing yourself, those actions are added to the actions list in the FirstResponder object in the IB. 通过从IB拖动或自己编写来创建IBAction时,这些操作将添加到IB中FirstResponder对象的操作列表中。 Next step is to drag a menu item from object library to menu bar and then right click firstResponder object and search for the action you want and connect it to menu bar item, you recently added. 下一步是将菜单项从对象库拖到菜单栏,然后​​右键单击firstResponder对象并搜索所需的操作并将其连接到最近添加的菜单栏项。

Here is the screenshot. 这是截图。 IB的截图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM