func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// On inputing value to textfield
if ((textField.text?.characters.count)! < 1 && string.characters.count > 0 ){
let nextTag = textField.tag + 1
// get next responder
var nextResponder = textField.superview?.viewWithTag(nextTag)
if (nextResponder == nil){
nextResponder = textField.superview?.viewWithTag(1)
}
textField.text = string;
//resign at 4th textfield
if textField.tag == 4{
txt4.resignFirstResponder()
}else{
nextResponder?.becomeFirstResponder()
}
return false
}
}
试试上面的代码,我已经拿了 4 个 UITextFields 并将其辞职到最后一个文本字段,你可以拿多少你想要的。