简体   繁体   中英

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).

I found a solution telling that I should connect the menu item to First Responder. Then the First Responder to IBAction, since First Responder presents on every scenes. So, the First Responder can receive action from menu bar first as nil then chain it to IBAction.

I however cannot figure out how to connect menu item to First Responder and First Responder to IBAction. When I ctrl+dragged menu item to First Responder, it shows only preset actions. And I cannot ctrl+drag ViewController to First Responder on viewController scene at all.

How do I connect IBAction and menu item to 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. 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.

Here is the screenshot. IB的截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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