Search code examples
objective-ccocoanscolor

NSColorWell doesn't open when bound with ValueTransformer


I have an NSColorWell, which is bound to a property that contains an NSString instance, which get's transformed into an NSColor through my ColorTransformer (NSValueTransformer). It essentially transforms something like #FF0000 into an NSColor. This works as expected, but the ColorWell no longer opens it's Pane when clicked. When I disable the binding, it works again. Any clues to what I'm doing wrong here?


Solution

  • return YES in

    +(BOOL)allowsReverseTransformation

    the apple docs example has it return NO, however the default implementation has it return YES. The reasoning behind this is in theory simple enough: apple doesn't want your users to be able to set a color which will then crash the app (being that a reverse transform was not implemented). You should then probably implement

    - (id)reverseTransformedValue:(id)value
    

    to make sure this doesn't happen, if you haven't done so already. (If you don't apple's docs say it will call - (id)transformedValue:(id)value)