问题
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