0

I have an NSMenuItem that I want to connect to an IBAction. The IBAction is in an NSViewController subclass. There's no direct link to that subclass from MainMenu.xib, so I can't choose it as a target for the NSMenuItem. The only actions I can choose are the ones that are exposed in the app delegate. Seems to me like jamming all the menu actions for different parts of the app into the app delegate is not very elegant. Is there another way to make this work?

jsd
  • 7,673
  • 5
  • 27
  • 47

2 Answers2

0

The xib can have an object with your NSViewController subclass. Drag a new Object into the xib, then set its class (in the Identity inspector) to your subclass. If that's what you're asking.

mikeD
  • 185
  • 1
  • 6
  • If I create an object in the xib to receive the action, will I need an IBOutlet for it, and then pass it to all the relevant places in the app? Or can I just create new instances of that class? – jsd Mar 17 '14 at 20:09
  • When you set the object's class to the class (your NSViewController subclass) that has the action you want to hook up to, that object will have its actions available in the xib just like the App delegate does. That's what I think you wanted in your original question. – mikeD Mar 18 '14 at 00:07
0

Drag your action to the "First Responder" object.

Messages are sent along the responder chain until it finds the first object that responds to it.

c.f. nil-targetted actions

NSGod
  • 22,699
  • 3
  • 58
  • 66
Abizern
  • 146,289
  • 39
  • 203
  • 257