On 22 Jan 2010, at 04:06, Graham Cox wrote:

> I have text fields which use NSNumberFormatters that occasionally need to 
> show a mixed value.
> 
> My preferred design is that when they contain a mixed value, they show '--'. 
> My problem is that I can't seem to get the formatters to return this string. 
> For example, the formatter has the 'nil symbol' and 'NaN symbol' set to this, 
> but calling [textField setObjectValue:nil] doesn't display it. If I try and 
> directly set the field's string using [textField setStringValue:@"--"] the 
> formatter converts this to 0.
> 
> I've tried subclassing the formatter and directly attempting to detect nil or 
> [NSNull null] as the object value but it never works, because the object 
> passed is always an NSNumber with value 0 even if the field is set with a 
> string or nil.
> 
> Any ideas how I can achieve what I want here?
> 
I see the same behaviour when subclassing NSNumberFormatter.
- (NSString *)stringForObjectValue:(id)anObject always receives an NSNumber.

If you subclass NSFormatter directly then you can probably gain the control you 
need and detect the underlying object type.

http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/DataFormatting/Articles/CreatingACustomFormatter.html

Regards

Jonathan Mitchell

Developer
http://www.mugginsoft.com

> --Graham
> 
> 
> _______________________________________________
> 
> Cocoa-dev mailing list ([email protected])
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/jonathan%40mugginsoft.com
> 
> This email sent to [email protected]

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to