In article <3j7mu5Fos6ihU1@individual.net>,
Ulrich Hobelmann <firstname.lastname@example.org> wrote:
> Hi, I have a Cocoa Document-based application, and I edited the
> main menu (added a new entry). Now I'd like the new menu entry to
> invoke the action newUser: in the responder chain (actually, I
> want it to be sent to the current key-window MyDocument instance,
> but the responder chain should work for that).
> I added the action as IBAction to MyDocument.h and dragged it into
> Interface Builder. When I now try to set the action for the menu
> entry with target FirstResponder, my action doesn't show up :(
> Is there any way to set an arbitrary action in Interface Builder?
> If not, how do I set the action for a menu item (yes, I could
> look that up I guess), and most of all, *where* would I put that
> init code?
Yes. Select the First Responder "numeral one" instance. Then switch the
current pane of that window to "Classes". The class "First Responder"
should be selected. If it isn't, select it. Then, use the Contextual
menu by <Control>Clicking on "First Responder". Choose "Add Action".
That will bring up the actions inspector, and let you add arbitrary
actions. Then, connect the menu item to the first responder the usual
At runtime, the app will do a
[NSApp sendAction: @selector(mymenuCommand:) to: nil sender:
which will walk the responder chain looking for the first object that
can handle that selector.
People usually keep their entire menu bar in their main nib, separate
from their document's nib, and just let the fact that the current
document is in the responder chain handle it.
David Phillip Oster