Skip navigation.
 
mlNSNumberFormatter Changes Reflected In NSTextField
FROM : Simon Wolf
DATE : Fri May 09 17:59:17 2008

I have an NSTextField with an associated NSNumberFormatter which I am 
using to format the values shown to a specific number of decimal 
places. I have a second NSTextField which I am using to display and 
edit the number of decimal places that I want shown and I have used 
the controlTextDidEndEditing delegate method to detect a change. Upon 
a change I am using the setMinimumFractionDigits and 
setMaximumFractionDigits methods of the NSNumberFormatter to change 
the number of decimal places to be shown but I am having trouble 
getting the NSTextField to refresh without giving the control the focus.

If I change the value of the field then the value is displayed 
correctly:

float temp;
temp = [netAmountField floatValue];
temp++;
[netAmountField setIntValue:(int)temp];

If I don't actually change the value then the NSTextField is not 
refreshed:

[netAmountField setFloatValue:[netAmountField floatValue]];

I'm fairly sure that this is simply due to the NSTextField being 
clever enough to realise that the value has not changed and therefore 
it doesn't re-display the value and trigger the new format and I am 
equally sure that I'm missing a simple way to achieve the refresh but 
after an hour of messing around I though I'd ask wiser folk.

Many thanks.

Simon

Related mailsAuthorDate
mlNSNumberFormatter Changes Reflected In NSTextField Simon Wolf May 9, 17:59
mlRe: NSNumberFormatter Changes Reflected In NSTextField Simon Wolf May 12, 18:19