BSD

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • NSPopUpButton Crashing When NSBackgroundColorAttributeName Is Set

    0 answers - 5342 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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 value:
    [NSColor whiteColor] range:NSMakeRange(0, [coloredTitle length])];
    NSMenuItem *newItem = [[NSMenuItem alloc] initWithTitle:
    [[newSequenceItem sourceTrack] readableName] action:nil
    keyEquivalent:@""];
    [newItem ];
    [[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 NS, not
    NSView subclasses). I thought I could make it work by adding this line:
    [coloredTitle 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 (Cocoa-dev (AT) lists (DOT) apple.com)
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com
    This email sent to bsdarchive (AT) developershed (DOT) com

Re: NSPopUpButton Crashing When NSBackgroundColorAttributeName Is Set


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "BSD"

EMSDN.COM