• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
nil NSFont from fonts popup
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nil NSFont from fonts popup


  • Subject: nil NSFont from fonts popup
  • From: Jeremy Dronfield <email@hidden>
  • Date: Wed, 31 Jul 2002 19:13:14 +0100

I'm having trouble with my own-rolled font menu (in a popup button).
Selection of certain fonts from the menu (usually but _not always_
graphic fonts like Symbol or Animals) raises a "nil NSFont given" error.
This is how the menu is implemented:

- (void)awakeFromNib
{
int fontsCount;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
NSArray *fontsArray = [[NSArray alloc] initWithArray:[fontManager
availableFontFamilies]];
NSArray *sortedFontsArray = [fontsArray
sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for (fontsCount = 0; fontsCount < [sortedFontsArray count];
fontsCount++) {
if (![[[sortedFontsArray objectAtIndex:fontsCount]
substringToIndex:1] isEqualToString:@"#"]) {
[fontMenuPopUp addItemWithTitle:[sortedFontsArray
objectAtIndex:fontsCount]];
}
}
[fontsArray release];
}

- (IBAction)fontChoiceAction:(id)sender
{
NSFont *chosenFont;
NSFontManager *fontManager = [NSFontManager sharedFontManager];
chosenFont = [fontManager convertFont:[[notepad textView] font]
toFamily:[sender titleOfSelectedItem]];
[[notepad textView] setFont:chosenFont];
[prefs setObject:[sender titleOfSelectedItem] forKey:@"Font Pref"];
}

I've tried to filter out invalid fonts by using -availableFontFamilies
rather than -availableFonts, and adding the -if statement to get rid of
families starting with "#", but family names which should return valid
fonts are returning nil. What am I doing wrong?
-Jeremy

=======================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at http://freespace.virgin.net/jeremy.dronfield
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Accessor methods and (auto)release <Memory trail>
  • Next by Date: Re: Accessor methods and (auto)release <Memory trail>
  • Previous by thread: Re: cocoa-dev digest, Vol 2 #1027 - 8 msgs
  • Next by thread: -LoginHook & -LogoutHook
  • Index(es):
    • Date
    • Thread