Pergunta

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?

Foi útil?

Solução

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];    
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top