validModesForFontPanel 从未调用过

发布于 2025-01-07 14:28:02 字数 918 浏览 4 评论 0原文

我有一个使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2025-01-14 14:28:02

您没有为小组指示任何响应者,而只是为经理指示。
这应该可以做到:

NSFontPanel* fontPanel = [fontManager fontPanel:YES];
[fontPanel setDelegate:self];    
[fontPanel makeKeyAndOrderFront:sender];    

You arent indicating any responder for the panel, just for the manager.
this should do it:

NSFontPanel* fontPanel = [fontManager fontPanel:YES];
[fontPanel setDelegate:self];    
[fontPanel makeKeyAndOrderFront:sender];    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文