Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting Menu Items in Document Based Applications

I've already asked a couple questions on this topic, and haven't really received a real answer on how to do it (it actually received the "Tumbleweed Badge" lol).

I have a document based application (meaning the Menu.Xib is separate from MyDocument.Xib).

Say I want to add a 'Bold' button, or a Check Spelling button (items that are listed in Menu.xib (under Format > Font etc) to MyDocument (the primary interface). I cannot figure out how to do this.

Any help would be greatly appreciated (I will reward an answer immediately if it works, this has stumped me for a couple weeks now).

I tried adding a Font Manager to MyDocument.Xib and connecting that way, but the Bold button only enables, it doesn't disable. Plus, Spell Check etc can't be activated via Font Manager.

There has to be a better way to do this.

The Apple Documentation is incredibly vague.

like image 672
Zakman411 Avatar asked Feb 03 '11 22:02

Zakman411


1 Answers

This is exactly what the First Responder object in IB is for. It is a proxy object for connecting actions. Any action messages sent to it will be passed down the responder chain to the first oobject that accepts them. For document based applications, the responder chain includes the current document. So, to connect the menu item to your document:

  1. Add the action to First Responder, if needed. You can do this from IB's inspector window.
  2. Connect the action to First Responder as if it were a normal object.
  3. Implement the action method in your document.

If you need to add a message to the first responder programatically, set the object's target to nil.

like image 112
ughoavgfhw Avatar answered Oct 16 '22 07:10

ughoavgfhw