tags:

views:

303

answers:

1

i have a UIView with 10 UITextFields on it.i want to limit the different max character length on each UItextField.suppose on the first textfield the max length should be 17,for second and third it should be 2.how do i achieve this?

+1  A: 

Implement a UITextViewDelegate with textView:shouldChangeTextInRange:replacementText and return NO when the length of the text view's content is equal to or greater than the maximum length. The only exception to this is when the replacementText is empty in which case you should always return YES

freespace
i have already implemented the method you mention above but it max limit is same for all uitextfields.i want different for different textfields
Rahul Vyas
You can either use a different delegate for each text view, or use the same delegate but differentiate between different text views
freespace
how do i do this mean use the same delegate but differentiate between different text views
Rahul Vyas
Store pointers to each text view somewhere, when the function is called the text view which triggered the method is passed in. Compare the passed in pointer against the pointers you have and determine which character limit you need to apply.
freespace
could you please post a sample code
Rahul Vyas
post your attempts at implementing my answer.
freespace