Re: NSNumberFormatter question - showing mixed state
Re: NSNumberFormatter question - showing mixed state
- Subject: Re: NSNumberFormatter question - showing mixed state
- From: Graham Cox <email@hidden>
- Date: Sat, 23 Jan 2010 12:02:28 +1100
On 23/01/2010, at 2:19 AM, email@hidden wrote:
> 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
Ah, thanks - that was the push in the right direction I needed. Turns out if I override:
- (NSAttributedString *) attributedStringForObjectValue:(id) anObject withDefaultAttributes:(NSDictionary*) attributes;
then <anObject> is a string if it has been explicitly set as a string, so I can detect that and return it instead of converting it to a number. It doesn't get nil if I set nil, that is converted to a number = 0 earlier it seems. But this is good enough - I can set a string for the mixed value.
thanks!
--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