Re: NSNumberFormatter and 10.4 behavior
Re: NSNumberFormatter and 10.4 behavior
- Subject: Re: NSNumberFormatter and 10.4 behavior
- From: Ricky Sharp <email@hidden>
- Date: Tue, 17 Jul 2007 17:35:34 -0500
On Jul 17, 2007, at 1:13 PM, Lee Ann Rucker wrote:
NSNumberFormatter and 10.4 behavior has got me rather confused.
I have a sample app with a custom number formatter that sets 10.4
behavior in its initialize function and nowhere else; that causes
the formatter to get 10.4 behavior even though it's created in the
nib (despite the doc saying formatters created in the nib get 10.0
behavior). Without that line, it gets 10.0.
But I try the same thing in my real app, and I get 10.0. Of course,
my real app has a lot more NSTextFields with numbers in them, and
most of them use the default NSNumberFormatter.
I've got a line to do
[NSNumberFormatter
setDefaultFormatterBehavior:NSNumberFormatterBehavior10_4];
in applicationWillFinishLaunching, but that doesn't help. Even with
initialize setting it to 10.4, it's 10.0.
Tried creating the formatter in code instead of the nib and
discovered that even though I'd already called [NSNumberFormatter
setDefaultFormatterBehavior: once, it was getting called again,
from [NSNumberFormatter initialize], and getting reset to 10.0.
Added code to set it *again* in my custom formatter initialize, and
now the custom formatter is 10.4, but creating NumberFormatters in
code is not so clean as in nibs; the bindings are clumsier in code.
Originally I just did
numberFormatter = [nibTextField formatter];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
but a co-worker didn't like that, because we'd have to remember set
it for every formatter we ever use.
I think you're going to be stuck in setting the behavior manually on
all instances that live in nibs.
I just tried a test app with this code:
@interface MyController : NSObject
{
IBOutlet NSTextField* textField;
}
@end
@implementation MyController
+ (void)initialize
{
if (self == [MyController class])
{
[NSNumberFormatter
setDefaultFormatterBehavior:NSNumberFormatterBehavior10_4];
NSLog (@"MyController initialize - default behavor = %d",
[NSNumberFormatter defaultFormatterBehavior]);
}
}
- (void)awakeFromNib
{
NSLog (@"MyController awakeFromNib");
}
- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
NSLog (@"applicationDidFinishLaunching - default behavior = %d",
[NSNumberFormatter defaultFormatterBehavior]);
NSNumberFormatter* theFormatter = [[[NSNumberFormatter alloc]
init] autorelease];
NSLog (@"runtime instance behavior = %d", [theFormatter
formatterBehavior]);
NSLog (@"nib instance behavior = %d", [[textField formatter]
formatterBehavior]);
}
Output always is:
MyController initialize - default behavor = 1040
MyController awakeFromNib
applicationDidFinishLaunching - default behavior = 1040
runtime instance behavior = 1040
nib instance behavior = 1000
I would call this a bug; one should be able to set the default
behavior even for formatters that will be loaded from nibs.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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