• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Limit NSTextField Size of Input
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Limit NSTextField Size of Input (From: "Sean Liong" <email@hidden>)

  • Prev by Date: Re: NSNotification for screen resolution change?
  • Next by Date: Re: I can't figure out how to use NSIndexSet
  • Previous by thread: Limit NSTextField Size of Input
  • Next by thread: Re: Limit NSTextField Size of Input
  • Index(es):
    • Date
    • Thread