Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 784
C. Pave Avatar asked May 11 '16 16:05

C. Pave


1 Answers

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. screenshot of IB

like image 73
Khundragpan Avatar answered Sep 16 '22 15:09

Khundragpan