setNilValueForKey: not called when Number Formatter is nil

  • OK, so I have an table view text cell that has a number formatter
    attached in Interface Builder. In order to protect against throwing an
    exception, I've overridden setNilValueForKey: as follows:

    - (void)setNilValueForKey:(NSString *)key
    {
        NSLog(@"setNilValueForKey: has been successfully called...");
        if ([key isEqual:@"dollarValue"])
      {
    [self setDollarValue:0.00];
      } else {
      {
    [super setNilValueForKey:key];
      }
    }

    dollarValue is a float and is KVC/KVO compliant (with a getter and
    setter) and setNilValueForKey: was overridden in the same class.

    The table view text cell updates properly so long as an empty value
    (aka 'nil') is not attempted (which results in a format error even
    though setNilValueForKey: has been overridden). The NSLog statement
    within setNilValueForKey: some unknown reason never gets called. I've
    also performed a "Clean All" and still the same results.

    I'm probably missing the obvious, but too tired to fight it right now.

    Any thoughts would be greatly appreciated.

    Thanks in advance,

    Marc
  • 8/17/08 2:42 AM, also sprach <mgb99...>:

    > The table view text cell updates properly so long as an empty value
    > (aka 'nil') is not attempted (which results in a format error even
    > though setNilValueForKey: has been overridden). The NSLog statement
    > within setNilValueForKey: some unknown reason never gets called. I've
    > also performed a "Clean All" and still the same results.

    The formatter is called before your model receives the update message. See
    the bindings message flow
    <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Con
    cepts/MessageFlow.html#//apple_ref/doc/uid/TP40002149-186285
    >

    If a nil value is allowed, you should let it pass your formatter's
    validation.

    HTH,

    Keary Suska
    Esoteritech, Inc.
    "Demystifying technology for your home or business"
  • THX Keary, but I'm thinking that this is either a bug or not the
    proper way to approach the 'nil' issue when dealing with an app that
    is 10.4+. The reason I say this is that, when I switch the formatter
    in IB from Mac OS X 10.4+ to Mac OS X 10.0+ in the Number Formatter
    Attributes, setNilValueForKey: gets called, the NSLog message
    displays, and the nil value gets set to 0.00 just as it should be.

    Anyone know if this approach is deprecated and, if so, how it should
    be handled for apps that are 10.4+ only. Otherwise, I'll file a Radar
    Bug Report.

    Thanks again,

    Marc

    On Aug 17, 2008, at 8:06 AM, Keary Suska wrote:

    > 8/17/08 2:42 AM, also sprach <mgb99...>:
    >
    >> The table view text cell updates properly so long as an empty value
    >> (aka 'nil') is not attempted (which results in a format error even
    >> though setNilValueForKey: has been overridden). The NSLog statement
    >> within setNilValueForKey: some unknown reason never gets called. I've
    >> also performed a "Clean All" and still the same results.
    >
    > The formatter is called before your model receives the update
    > message. See
    > the bindings message flow
    > <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Con

    > cepts/MessageFlow.html#//apple_ref/doc/uid/TP40002149-186285>
    >
    > If a nil value is allowed, you should let it pass your formatter's
    > validation.
    >
    > HTH,
    >
    > Keary Suska
    > Esoteritech, Inc.
    > "Demystifying technology for your home or business"
previous month august 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today