iphone - TextField:shouldChangeCharactersInRange:replacementString: return trap! -


im calling uitableviewcell delegate method textfield:shouldchangecharactersinrange:replacementstring: on custom cell has 4 uitextfields , happening once maxlength reached on 1 of fields dose not let enter text in other fields because returning "no" initial if statement thats being satisfied. ideas on how around this?

i'm testing on 2 fields @ moment. thank in advance.

- (bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string {     int regfieldonelength = [regfieldone.text length] ;     int regfieldtwolength = [regfieldtwo.text length] ;       if ((regfieldonelength >= maxlength && ![string isequaltostring:@""]) || (regfieldtwolength >= maxlength && ![string isequaltostring:@""])) {         if(regfieldone.text = [regfieldone.text substringtoindex:maxlength]){             return no;         }         if(regfieldtwo.text = [regfieldtwo.text substringtoindex:maxlength]){             return no;         }     }       return yes; } 

why using booth text field, instead use current text field being edited

    -(bool)textfield:(uitextfield *)textfield shouldchangecharactersinrange:(nsrange)range replacementstring:(nsstring *)string     {         int currenttxtlen = [textfield.text length] ;         if (currenttxtlen >= maxlength && ![string isequaltostring:@""]) {             return no;         }         return yes; } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -