In IB in the Library panel, just below half way down there is a symbol on the left hand side which is a dollar sign ( and a calendar symbol next to it ) which is the number formatter. Click this and drag it to the text field - and drop it on it. Once the formatter is applied to the text field there is a small circle to the lower right of the edge of the text field - with a dollar in it. Click this symbol and the formatter setup panel will appear in the Attributes Inspector. Set away !

There is however a slight problem in using formatters for input. If you set it for numbers only, when the user types in an illegal character ( something other than a digit ) and tries to tab out of the field, they simply can't escape. Likewise if you set a target / action and they try to press return to complete the entry. There must be ways of frigging with the formatter to change this - but I've never bothered.

Instead of using a formatter, if I want to collect digits from the user I simply subclass the NSTextField and override - (void)textDidChange:(NSNotification *)aNotification. Then every time the user enters something you can check what they have written and either allow it or not.

For example to convert input to uppercase I do the following :-


-(void)textDidChange:(NSNotification *)aNotification
{
        if( [upperCaseBtn  state] == NSOnState )
        {
                [self  setStringValue:[[self  stringValue]  uppercaseString]];
        }
}



peter
_______________________________________________

Cocoa-dev mailing list ([email protected])

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 [email protected]

Reply via email to