Trouble with First Responder

[亡魂溺海] 提交于 2020-01-15 12:48:28

问题


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


回答1:


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 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) 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].



来源:https://stackoverflow.com/questions/4906110/trouble-with-first-responder

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