Why can't I connect my menu to my IBAction view controller?
Since your menu items and the view controller are in different scenes in the storyboard. You can imagine the scene as an independent graph of objects that are created when loading a scene from the storyboard. Objects in different scenes cannot be joined together in a storyboard because they do not load at the same time.
Just for fun, try creating an instance of your view controller in the Scene application in your storyboard. To do this, you probably have to drag a simple vintage instance of NSObject into the scene, and then set its type. As soon as you do this, you will find that you can drag the connection from the menu item to this view controller as you would expect, but you cannot drag the connection to another object of the same type in another scene.
Note. After you have played enough to convince yourself that it works, be sure to remove the added view controller. A view controller without a view is like a duck without a charlat, and a view controller and its view hierarchy should be in their own scene.
My 2 cents suggest that this is because the application is document-based
No, this has nothing to do with it. You will have the same problem in an application that is not document based. You will also have the same problem if your application was based on xix instead of using storyboards, since the controller you are trying to connect to would be in a completely different .xib file.
A simple solution, as Mark has already pointed out, is to use a chain of defendants. The First Responder proxy object is part of every scene, so you can always connect to it. When you connect a menu item to the first responder, its target will be nil , which tells NSMenu to go through the chain of responders until it finds an object that responds to the message about the action of the menu item. Then it sends a message to this object.
Caleb
source share