• 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: filtering NSTextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: filtering NSTextField


  • Subject: Re: filtering NSTextField
  • From: john <email@hidden>
  • Date: Thu, 31 Aug 2006 19:03:13 -0400

Hi Hans,

You'll want to register for a notification to be notified when the text changes, as such:

[[NSNotificationCenter defaultCenter] addObserver: self
        selector: @selector(textDidChange:)
        name: NSControlTextDidChangeNotification
        object: textField];

Then in your textDidChange: method (or whatever you name it), you can modify the input. For instance, to ensure uppercase:

[[textField setStringValue: [[textField stringValue] uppercaseString]];

If you want to limited the amount of digits, you can just use the deleteCharactersInRange: method of NSMutableString. If you're wanting to limit the kind of text you find in the text field, you can use an NSMutableCharacterSet with all of the characters that are allowed and then use NSScanner's scanCharactersFromSet:intoString method to filter out the unwanted characters.

Hope that helps.

-- John


I would like to filter the input for a textfield, so that only digits upto to a certain number will be accepted or to change the incoming text to all uppercase.
I searched the documentation but could not find how to proceed.
Can somebody point out to me where to start researching?


Hans van der Meer
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >filtering NSTextField (From: Hans van der Meer <email@hidden>)

  • Prev by Date: Re: +/- button(s)?
  • Next by Date: Re: termination
  • Previous by thread: Re: filtering NSTextField
  • Next by thread: termination
  • Index(es):
    • Date
    • Thread