在基于文档的应用程序中连接菜单项 [英] Connecting Menu Items in Document Based Applications

查看:105
本文介绍了在基于文档的应用程序中连接菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经问过几个关于这个话题的问题,并没有真正收到一个真正的答案(它实际上收到了Tumbleweed徽章lol)。



我有一个基于文档的应用程序(意味着Menu.Xib与MyDocument.Xib分开)。



说我想添加一个'Bold'按钮或Check Spelling按钮(在Menu.xib中列出的项目(在格式>字体等下)到MyDocument(主界面)。我不知道该怎么做。



任何帮助将非常感谢(如果它工作,我会立即奖励一个答案,这已经困了我几个星期现在)。



我试过将字体管理器添加到MyDocument.Xib并以此方式连接,但是Bold按钮仅启用,不会禁用,此外,无法通过字体管理器激活拼写检查等。



有一个更好的方法来做到这一点。



Apple文档非常模糊。

解决方案

这正是IB中第一个响应者对象的作用。它是用于连接操作的代理对象。发送到它的任何动作消息将在响应链中传递到接受它们的第一个oobject。对于基于文档的应用程序,响应器链包括当前文档。因此,要将菜单项连接到您的文档:


  1. 如果需要,将操作添加到First Responder。

  2. 将操作连接到第一响应者,就像它是一个普通的对象一样。

  3. 在IB的检查器窗口中实现操作方法


  4. 如果您需要以编程方式向第一个响应者添加消息,请将对象的目标设置为 nil


    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.

    解决方案

    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.

    这篇关于在基于文档的应用程序中连接菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆