• 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: Setting a delegate on a UITextField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting a delegate on a UITextField


  • Subject: Re: Setting a delegate on a UITextField
  • From: Matt Neuburg <email@hidden>
  • Date: Sat, 05 Mar 2011 11:22:46 -0800

On Thu, 03 Mar 2011 18:51:39 -0800 (PST), Dianne <email@hidden> said:
>there is, you need to use a formatter for that, you can even set the allowed
>characters to be inputted to the textfield.
>check NSFormatter if it is of any help, you can also extend the class to adjust
>to your needs.
>________________________________
>From: Jon Sigman <email@hidden>
>To: Cocoa Developers <email@hidden>
>Sent: Fri, March 4, 2011 10:29:23 AM
>Subject: Re: Setting a delegate on a UITextField
>
>Okay, part II:
>
>Is there a way to allow only a certain number of characters in a UITextField?
>Should this be done in the -textFieldDidEndEditing delegate callback, with an
>alert to the user, or just truncating the field, or ...?
>

But that's not such a good answer for iOS (this is a UITextField, not an NSTextField) because you can't attach a formatter to a text field there. It's a pity, but there it is. You're going to have to make a design decision and it isn't going to be pleasant. :(

One possible approach on iOS is to implement textFieldShouldEndEditing, and return NO and put up an alert if there's a problem. Another is just to make the change yourself in textFieldDidEndEditing. See the section entitled "Validating Entered Text" (along with the preceding section) in the "Managing Text Fields and Text Views" chapter of the Text, Web, and Editing Programming Guide for iOS.

m.

--
matt neuburg, phd = email@hidden, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook_______________________________________________

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

  • Prev by Date: Re: Accepting current edited text field contents
  • Next by Date: Re: Accepting current edited text field contents
  • Previous by thread: Re: Setting a delegate on a UITextField
  • Next by thread: Re: Setting a delegate on a UITextField
  • Index(es):
    • Date
    • Thread