0

I have two textfield. Using this It works great to set the max character to textfield. How I can check what textfield is been used, in order to set differents max lenghts?

Community
  • 1
  • 1
doxsi
  • 1,002
  • 19
  • 42

1 Answers1

2

I think you are trying to set different maximum character lengths for your textfields, then first of all, create outlet for your textfield in header,

//header
IBOutlet UTtextField *textField1;
IBOutlet UITextField *textField2;

Hope you have already done it.

Then just check the textField in the implementation method, I will modify the answer with:

  - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        if(textField == textField1) {
                NSUInteger newLength = [textField.text length] + [string length] - range.length;
            return (newLength > 25) ? NO : YES;
        }
        else if(textField == textField2)
       {
               //do the same with different values
       }
 }

EDIT You can also set tags for your TextFields and make use of it, like switch(textField.tag).

DD_
  • 7,230
  • 11
  • 38
  • 59