急救人员遇到问题
我在基于文档的应用程序(即粗体、斜体等)中实现一些快捷方式时遇到了一些麻烦:
问题是所描述的方法将实际的“粗体”菜单项与字体管理器断开连接,并将其替换为我创建的操作(在本例中, 粗体
)。因为只能有一个发送的动作,所以它是被替换的,而不是添加的。我怎样才能克服这个问题?非常令人沮丧。如果有人可以帮助我,我将不胜感激。
扎克
I've had some trouble implementing some shortcuts in a document based application (i.e. Bold, Italic etc) available here:
Connecting Menu Items in Document Based Applications
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您不能让一个菜单触发两个操作,因此有两种好方法可以解决此问题:
1) 让您的
boldIt:
操作在NSFontManager
中调用适当的方法。完成了它的工作。这里的缺点是无论调用什么boldIt:
都需要了解字体管理器。2) 子类 NSFontManager 并重写
addFontTrait:
以包含选择“粗体”时所需的行为,然后使用[super addFontTrait:sender]
。Since you can't have a menu trigger two actions, there's two good ways to approach this:
1) Have your
boldIt:
action call the appropriate method in theNSFontManager
when it's done with it's work. The drawback here is that whateverboldIt:
is called on needs to know about the Font Manager as well.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]
.