validModesForFontPanel 从未调用过
我有一个使用 NSFontPanel
的应用程序。 我像这样打开字体面板:
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[fontManager orderFrontFontPanel:self];
[fontManager setDelegate:self];
[fontManager setTarget:self];
[fontManager setAction:@selector(changeFont:)];
然后我有一个 -(void)changeFont:(id)sender
方法,该方法对面板中的字体更改做出反应。这一切都运作良好。
现在,我想禁用一些字体选项,因此我实现了 NSFontPanelValidation
协议的 validModesForFontPanel
方法:
- (NSUInteger)validModesForFontPanel:(NSFontPanel *)fontPanel {
NSLog(@"validModesForFontPanel");
return NSFontPanelFaceModeMask | NSFontPanelCollectionModeMask | NSFontPanelSizeModeMask;
}
但是,该方法永远不会被调用。 在文档中它说:“此消息沿着响应者链发送到实现该方法的第一个响应者。理想情况下,该对象应该是发现的也实现了changeFont的第一个响应者:。”
我确实实现了< code>changeFont 在此响应程序中,因此除非有其他我不知道的响应程序,否则我不知道此消息会发生什么。
有人有什么建议吗?
I have an application where I use the NSFontPanel
.
I open the font panel like this:
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[fontManager orderFrontFontPanel:self];
[fontManager setDelegate:self];
[fontManager setTarget:self];
[fontManager setAction:@selector(changeFont:)];
I then have an -(void)changeFont:(id)sender
method which reacts to font changes in the panel. This all works well.
Now, I want to disable some of the font options, so I implement the validModesForFontPanel
method of the NSFontPanelValidation
protocol:
- (NSUInteger)validModesForFontPanel:(NSFontPanel *)fontPanel {
NSLog(@"validModesForFontPanel");
return NSFontPanelFaceModeMask | NSFontPanelCollectionModeMask | NSFontPanelSizeModeMask;
}
However, the method never gets called.
In the documentation it says: "This message is sent up the responder chain to the first responder implementing the method. Ideally that object should be the first responder found that also implements changeFont:."
I do implement changeFont
in this responder, so unless there is some other responder which I am not aware of, I don't know what happens to this message.
Does anyone have any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有为小组指示任何响应者,而只是为经理指示。
这应该可以做到:
You arent indicating any responder for the panel, just for the manager.
this should do it: