Connecting Menu Items in Document Based Applications

北城余情 提交于 2019-12-14 00:30:40

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/4892705/connecting-menu-items-in-document-based-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!