0

In IB i inserted a configured NSNumberFormatter to the NSTextField, which validates users number input

All works fine, when i input a text or a number which is too large - i get the warning prompt

However, when the user deletes the value using back, the NSNumberFormatter raises for

[NSNull doubleValue]

as it gets the NSNull value

How to configure the nil value handling for numbers? I assigned the null placeholder, but this apparently doesn't stop the exception from happening

  • the desired behavior is to don't validate nil and / or don't throw an exception
Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179

1 Answers1

0

1) Subclass NSNumberFormatter

2) Implement (will put a 0, if empty)

- (NSString *)stringForObjectValue:(id)obj {

    if (obj == nil) {
        return @"0";
    }

    return [super stringForObjectValue:obj];

}

3) set the class in IB

Peter Lapisu
  • 19,915
  • 16
  • 123
  • 179