On Dec 22, 2008, at 9:11 AM, Avery Nickelby wrote:

I've looked through the archives and the documentation; most of the
information is related to using NSNumberFormatter programatically. I am
looking for a good explanation for using 10.4 style data formatters in
Interface Builder; when I configure a number data formatter I can only get one of two behaviors (I've tried different permutations of the switches in
IB):
1) User MUST type in a currency symbol before the field accepts input. The
information is displayed as $123.45.
2) The user doesn't type in a currency symbol. The information is just
displayed in decimal format (123.45)

I want: The user types in a number. The formatter looks up the appropriate
currency symbol tied to the user-defined default locale and displays a
locale-specific format.

How do I get this behavior? Do I need to revert to the old style (which I
can get to work)?

Thanks

Avery

Unfortunately, the 10.4 formatter will not do what you want using IB only.

If you put the following method in your controller and set it as the delegate of the NSTextField, it will add the currency symbol when the user tab/enter/return/clicks out of the field. Basically, it tells the formatter to format the number in the NSTextField's string (why it can't do that itself I'm not sure), but only if the currency symbol is not already there.

- (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string errorDescription:(NSString *)error
{       
        if ([[control formatter] isKindOfClass:[NSNumberFormatter class]])
        {
                NSNumberFormatter *formatter = [control formatter];

if ([formatter numberStyle] == NSNumberFormatterCurrencyStyle && ! [string hasPrefix:[formatter currencySymbol]])
                {
[control setStringValue:[formatter stringFromNumber:[NSNumber numberWithDouble:[string doubleValue]]]];
                }
        }
        
        return YES;
}

-- Nathan





_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to