2
핀 코드에 대해 각각 1 자릿수를 허용하는 4 개의 텍스트 필드가 있습니다. 번호를 입력 할 때마다 자동으로 네 번째 자릿수의 마지막 텍스트 필드에 도달 할 때까지 두 번째 자릿수의 다른 텍스트 필드로 이동합니다. 이것은 잘 작동합니다. 그러나 숫자 패드에서 삭제 (x) 버튼을 클릭하면 숫자를 변경하고, 4 번째 텍스트 필드에 있지 않으면 숫자가 삭제되지 않습니다. 그 다음에는 3 번째, 2 번째, 1 번째 텍스트 필드 삭제 (x) 버튼을 누르는 한.키보드의 x 버튼을 누르는 한 다른 텍스트 필드에서 값을 삭제하는 방법
여기
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
// On inputing value to textfield
if ((textField.text?.count)! < 1 && string.count > 0){
if(textField == pinOne){
pinTwo.becomeFirstResponder()
}
if(textField == pinTwo){
pinThree.becomeFirstResponder()
}
if(textField == pinThree){
pinFour.becomeFirstResponder()
}
textField.text = string
if let actualText = textField.text {
let pinEntered: Character = Character(actualText)
concatString += String(pinEntered)
if concatString.count == 4 {
checkPin()
}
}
return false
} else if ((textField.text?.count)! >= 1 && string.count == 0){
// On Deleting value from Textfield
if(textField == pinTwo){
pinOne.becomeFirstResponder()
}
if(textField == pinThree){
pinTwo.becomeFirstResponder()
}
if(textField == pinFour) {
pinThree.becomeFirstResponder()
}
textField.text = ""
return false
}
}
이 도와주세요 코드입니다. 고맙습니다!
내가 같은 functionaliy을 구현하기 위해 https://github.com/varunpm1/VPMOTPView 라이브러리를 사용했다 . 그것은 다양한 옵션을 가지고 있습니다 .. 당신이 그것을 사용하고자하는 경우에 대비하여. –
@WasimMalek, 감사합니다. 나는 이것을 시도 할 것이다. – TSM
처음 세 핀 필드에있을 때이 방법을 단계적으로 수행하면 어떻게됩니까? 그리고 텍스트를 지운 후에'becomeFirstResponder'를 움직여보십시오. – zcui93