• 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
NSPopUpButton Crashing When NSBackgroundColorAttributeName Is Set
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPopUpButton Crashing When NSBackgroundColorAttributeName Is Set


  • Subject: NSPopUpButton Crashing When NSBackgroundColorAttributeName Is Set
  • From: email@hidden
  • Date: Sun, 21 Aug 2005 18:24:46 -0700

Hi, what I'm trying to do is have Cocoa UI elements with custom coloring for something of a "negative" look (light text on dark background), and the colors will need to change programatically during the program run. This works fine for things like NSTextFields where I can just set the background color to match my background or have them not draw the background so my background shows through. But I've run into a problem with NSPopUpButton. I'm using the style with "Bordered" unchecked in IB (it's flat and looks like an NSTextField when not popped up). By using this code I can correctly color the text for the menu item elements:

// must add to popup menu directly because [NSPopUpButton addItem:] method removes duplicates
NSMutableAttributedString *coloredTitle = [[NSMutableAttributedString alloc] initWithString:[[newSequenceItem sourceTrack] readableName]];
[coloredTitle addAttribute:NSForegroundColorAttributeName value: [NSColor whiteColor] range:NSMakeRange(0, [coloredTitle length])];
NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle: [[newSequenceItem sourceTrack] readableName] action:nil keyEquivalent:@""];
[newItem setAttributedTitle:coloredTitle];
[[trackNamesPopUp menu] addItem:newItem];


So this works great, EXCEPT I still have the light pinstripey background under the text when I click on the button to pop up the list. I can't find any way to get ahold of the view that gets popped- up when the button is clicked on, nor any of the menu item view rectangles (NSMenuItems and NSMenu are subclasses of NSObject, not NSView subclasses). I thought I could make it work by adding this line:

[coloredTitle addAttribute:NSBackgroundColorAttributeName value: [NSColor darkGrayColor] range:NSMakeRange(0, [coloredTitle length])];

but when I do, the app crashes. not when the line is called, but when the popup button is clicked on for the first time. Here is the error text with the crash:

2005-08-17 16:29:55.106 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x662b990]
2005-08-17 16:29:55.106 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x662b990]
2005-08-17 16:29:55.107 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b6be0]
2005-08-17 16:29:55.108 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b6be0]
2005-08-17 16:29:55.114 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b78c0]
2005-08-17 16:29:55.114 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b78c0]
2005-08-17 16:29:55.115 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b8c90]
2005-08-17 16:29:55.115 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b8c90]
2005-08-17 16:29:55.121 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b9ae0]
2005-08-17 16:29:55.121 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60b9ae0]
2005-08-17 16:29:55.123 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60ba810]
2005-08-17 16:29:55.123 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60ba810]
2005-08-17 16:29:55.126 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60bb990]
2005-08-17 16:29:55.127 Stinger[25650] *** -[_NSExistingCGSContext window]: selector not recognized [self = 0x60bb990]
2005-08-17 16:29:55.129 Stinger[25650] *** -[_NSExistingCGSContext focusView:inWindow:]: selector not recognized [self = 0x60bb990]
2005-08-17 16:29:55.132 Stinger[25650] *** -[_NSExistingCGSContext focusView:inWindow:]: selector not recognized [self = 0x60bb990]
2005-08-17 16:29:55.132 Stinger[25650] *** -[_NSExistingCGSContext popTopView]: selector not recognized [self = 0x60bb990]
2005-08-17 16:29:55.132 Stinger[25650] An uncaught exception was raised
2005-08-17 16:29:55.133 Stinger[25650] *** -[_NSExistingCGSContext popTopView]: selector not recognized [self = 0x60bb990]
2005-08-17 16:29:55.133 Stinger[25650] *** Uncaught exception: <NSInvalidArgumentException> *** -[_NSExistingCGSContext popTopView]: selector not recognized [self = 0x60bb990]


Stinger has exited due to signal 5 (SIGTRAP).

Now, what is interesting is that my popup button text does initially appear with the correct dark-grey background. So the line adding the background attribute does work. But when the button is clicked on, it barfs, as you can see. Bug? Bottom line is that I just want to be able to color both the text foreground and background as I like in an NSPopupButton, including in the popped-up view, so what's the best way to do that? I'd also like to color the little "up/down" arrows the same color as the foreground (text) if possible. Thanks in advance if you can help!

- Ben
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Help! Lost in XCode...
  • Next by Date: Re: Reporting errors from key-value-coding accessors
  • Previous by thread: NSPopUpButton Crashing When NSBackgroundColorAttributeName Is Set
  • Next by thread: nstoolbaritem coordinates?
  • Index(es):
    • Date
    • Thread