i'm trying develop a textfield switching from 1 to another automatically, similarly i can switch the textfield backwards, but in null state i can't switch the cursor into the previous textfield , i tried with EditingChange Event but when the textfield in null state the Editng Change function is not fired.
The code is :
@IBAction func textFieldEditingChanged(_ sender: UITextField) {
if(sender.text?.characters.count == 1) {
switch sender {
case otpField1:
otpField2.becomeFirstResponder()
case otpField2:
otpField3.becomeFirstResponder()
case otpField3:
otpField4.becomeFirstResponder()
case otpField4:
otpField4.resignFirstResponder()
default:
break
}
}else {
}
if ((sender.text?.characters.count)! <= 0 || sender.text! == "" || sender.text?.isEmpty == true) {
switch sender {
case otpField4:
otpField3.becomeFirstResponder()
case otpField3:
otpField2.becomeFirstResponder()
case otpField2:
otpField1.becomeFirstResponder()
case otpField1:
otpField1.resignFirstResponder()
default:
break
}
}
}
In order find
UITextField
empty you can useisEmpty
ofString
.So here it will be:
How I will use is
Hopes this solves your problem.