Re: Limit NSTextField Size of Input
Re: Limit NSTextField Size of Input
- Subject: Re: Limit NSTextField Size of Input
- From: Chris Hanson <email@hidden>
- Date: Thu, 20 Nov 2003 17:42:41 -0600
On Nov 20, 2003, at 3:57 PM, Sean Liong wrote:
This seem to be a rather easy NSTextField question, but I have
difficult to get it work.
How shall I limit the number of input to an NSTextField? For example,
I only want user to be able to key only maximum of 10 characters.
The easy way to do this is with a custom NSFormatter subclass. I
developed one for a client earlier this year that included an Interface
Builder palette. That way I could specify not just that a text field
should have my formatter in Interface Builder, but also use a custom
inspector for the formatter to specify the limits that should be
applied. I could also use my custom NSFormatter in table views etc. --
any place that any other NSFormatter could be used.
Another way to do this, if you also need to use a separate NSFormatter
on the text field (for instance an NSNumberFormatter or
NSDateFormatter) would be to subclass NSTextField or NSTextFieldCell,
and apply the limits in your subclass. Again, to make your life easier
if you're going to be doing a lot of this you might want to consider
building an Interface Builder palette.
Finally, you could put the limiting logic in an
NSControlTextDidChangeNotification handler or -controlTextDidChange:
delegate method. To make your life easier, you could probably create a
little custom class for applying the limits.
-- Chris
--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.