I want the user to be able to change the font NSTableViewbased on the view. I use Cocoa bindings and master data. In my test code, I have a method changeFont:that calls as soon as I press a key combination associated with a font, for example, cmd-Ior cmd-B, but so far I have not been lucky to change the actual font in the form of a table:
- (void)changeFont:(id)sender
{
NSFont *oldFont = [self.airportTableView font];
NSFont *newFont = [sender convertFont:oldFont];
NSLog(@"sender: %@ oldfont: %@, newFont: %@ fontmanager selected: %@, font panel selected: %@",
sender, oldFont, newFont, [sender selectedFont], [sender convertFont:[sender selectedFont]]);
[self.airportTableView setFont:newFont];
}
outputs the following result:
sender: <NSFontManager: 0x6080000b4580> oldfont: (null), newFont: (null) fontmanager selected: (null), font panel selected: (null)
Even this trivial code:
font = [NSFont boldSystemFontOfSize:12];
[self.airportTableView setFont:font];
NSFont *oldFont = [self.airportTableView font];
NSLog(@"oldfont: %@",oldFont);
only leads to:
oldfont: (null)
Can any soul provide some code that allows the user to change the font of the NSTableView?
source
share