ios - textfield auto focus not working properly -


i have 6 text field text box. , when user finish enter in first text field, should automatically have go second , on. here code hats not working. when enter value in first text field, values entering in second ..here code :

this below code have done enter 1 digit in each text field. here how can add text field responder...once finish first text field, adn on...

 func textfield(_ textfield: uitextfield, shouldchangecharactersin range: nsrange, replacementstring string: string) -> bool {           if textfield == self.cardtextfieldone{         guard let text = textfield.text else {return true}          let newlength = text.characters.count + string.characters.count - range.length         return newlength <= 1         }else if textfield == self.cardtextfieldtwo{             guard let text = textfield.text else { return true }              let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 1         }         else if textfield == self.cardtextfieldtwo{             guard let text = textfield.text else { return true }              let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 1         }         else if textfield == self.cardtextfieldthree{             guard let text = textfield.text else { return true }              let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 1         }         else if textfield == self.cardtextfieldfour{             guard let text = textfield.text else { return true }             let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 1         }         else if textfield == self.cardtextfieldfive{             guard let text = textfield.text else { return true }             let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 1         }         else if textfield == self.cardtextfieldsix{             guard let text = textfield.text else { return true }             let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 1         }         else if textfield == self.cardtextfieldmonth{             guard let text = textfield.text else { return true }             let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 2         }         else if textfield == self.cardtextfieldyear{             guard let text = textfield.text else { return true }             let newlength = text.characters.count + string.characters.count - range.length             return newlength <= 2         }         return true        } 

thanks in advance !!

update

 if textfield == self.cardtextfieldone{               guard let text = textfield.text else {return true}             let newlength = text.characters.count + string.characters.count - range.length              if  (string == "") || string.characters.count < 1             {                 return true //this allow backspace             }else if  (cardtextfieldone.text?.characters.count)! >= 1             {                 cardtextfieldone.resignfirstresponder();                 self.cardtextfieldtwo.becomefirstresponder()                  return false             }               return newlength <= 1             } 

simple solution

create method called every time change textfield text below can see in image, while right click on textfield, see editing change drag , create method enter image description here

 @ibaction func editing(_ sender: uitextfield)     {         if sender == yourfirsttextfield {             if sender.text?.characters.count == 1 {                 yournexttextfield.becomefirstresponder()             }         }      } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -