Re: NSNumberFormatter question - showing mixed state
Re: NSNumberFormatter question - showing mixed state
- Subject: Re: NSNumberFormatter question - showing mixed state
- From: "email@hidden" <email@hidden>
- Date: Fri, 22 Jan 2010 15:19:39 +0000
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@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden