Re: NSNumberFormattter not working
Re: NSNumberFormattter not working
- Subject: Re: NSNumberFormattter not working
- From: Ken Tozier <email@hidden>
- Date: Thu, 12 Jul 2007 10:59:22 -0400
Well I played around with a formatter in IB and apparently number
formatters don't prevent alpha entry they only beep on completion to
indicate that something is wrong.
I must be "fighting the framework" here, as I can't believe that
something so conceptually simple as restricting text input to only
valid numeric characters, would require delegates or overriding the
application's key handling mechanism. (Which is what several threads
at CocoaDev suggested)
I know the following NSTextField method doesn't exist, but is there
some reasonably simple technique that would simulate it's functionality?
[aTextField setValidCharacterSet: [NSCharacterSet
decimalDigitCharacterSet]];
TIA
Ken
On Jul 12, 2007, at 9:11 AM, Ken Tozier wrote:
Hi
I have a programatically generated NSTextField subclass and am
trying to set it's formatter in the subclass init method but it
doesn't seem to work. I can enter any character (even alphabetic,
punctuation etc) The text field is embedded in another custom view
so I created the following setter method to make setting the format
more direct
- (void) setFormatter:(id) inFormatter
{
[textField setFormatter: inFormatter];
}
The actual formatter is set up as a static global in the text field
container class like this
static NSNumberFormatter *gNumberFormatter = nil;
@implementation PMTokenView
+ (void) initialize
{
gNumberFormatter = [[NSNumberFormatter alloc] init];
// constrain input to values between 1 and 1000
[gNumberFormatter setMinimum: [NSNumber numberWithInt: 1]];
[gNumberFormatter setMinimum: [NSNumber numberWithInt: 1000]];
}
- (id) initWithFrame:(NSRect) inRect
{
self = [super initWithFrame: inRect];
if (self)
{
[self setFormatter: gNumberFormatter];
}
return self;
}
@end
Anyone point out what I'm doing wrong?
Thanks for any help
Ken
_______________________________________________
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:
40comcast.net
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