第一响应者的麻烦 [英] Trouble with First Responder

查看:152
本文介绍了第一响应者的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在基于文档的应用程序(即Bold,Italic等)中实现一些快捷方式时遇到了一些麻烦:

I've had some trouble implementing some shortcuts in a document based application (i.e. Bold, Italic etc) available here:

在基于文档的应用程序中连接菜单项

问题是所描述的方法将实际的粗体菜单项与字体管理器断开连接,并将其替换为我创建的操作(在本例中为 boldIt )。因为只能有一个发送动作,所以它被替换,而不是添加。我怎么能克服这个?非常令人沮丧。如果有人可以帮助我,我将非常感激。

The issue is that the method described disconnects the actual 'Bold' menu item from the Font Manager, and replaces it with my action I created (in this case, boldIt). Because there can be only one sent action, it is replaced, not added. How can I overcome this? Very frustrating. If anyone can help me I would greatly appreciate it.

Zach

推荐答案

由于你没有菜单触发两个动作,有两种方法可以解决这个问题:

Since you can't have a menu trigger two actions, there's two good ways to approach this:

1)你的 boldIt:当它完成它的工作时,动作调用 NSFontManager 中的相应方法。这里的缺点是,无论 boldIt:被调用,还需要知道字体管理器。

1) Have your boldIt: action call the appropriate method in the NSFontManager when it's done with it's work. The drawback here is that whatever boldIt: is called on needs to know about the Font Manager as well.

2 )子类NSFontManager并覆盖 addFontTrait:以在选择粗体时包含所需的行为,然后使用调用超类上的原始方法super addFontTrait:sender]

2) Subclass NSFontManager and override addFontTrait: to include your desired behaviour when 'Bold' is selected, and then call the original method on the super class with [super addFontTrait:sender].

这篇关于第一响应者的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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