我想檢查我目前的UITextField,並在編輯完成的情況下跳轉到下一個。如何在編輯完成後跳轉到下一個UITextField?
到目前爲止,我已經實現了此代碼,但由於某種原因無法正常工作。
重要提示:實際按預期工作的代碼是Robert方法,請參閱下文。由於我的名聲很低,我不能爲他投票。
新增:我用這來限制到一個字符
//Limit the length of the UITextfields
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
guard let text = textField.text else { return true }
let newLength = text.characters.count + string.characters.count - range.length
print("textField...shouldChangeCharactersInRange method called")
switch textField {
case rateTvA:
return newLength <= limitLength
case rateTvB:
return newLength <= limitLength
case rateTvC:
return newLength <= limitLength
// Do not put constraints on any other text field in this view
// that uses this class as its delegate.
default:
return true
}
}
注:我期待收到一張單字符每個的UITextField
func textFieldShouldEndEditing(textField: UITextField) -> Bool {
let charCount = textField.text!.characters.count
print("textFieldShouldEndEditing method called")
print("How many characters has been typed in? \(charCount)")
switch textField {
case rateTvA:
if(charCount > 0) {
rateTvB.becomeFirstResponder()
return true
}
case rateTvB:
if(charCount > 0) {
rateTvC.becomeFirstResponder()
return true
}
case rateTvC:
if(charCount > 0) {
rateTVD.becomeFirstResponder()
return true
}
default:
return false
}
return false
}
有你添加的UITextField委託? – casillas
它不起作用,由於某種原因不會觸發你的功能,我只是輸入字符,它不會跳。任何想法發生了什麼? ---請參閱我更新的帖子,其中包括限制長度的代碼。 – Carlos