- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *finalString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if ( [finalString length] > 0 ) {
textField.text = string;
UIResponder* nextResponder = [textField.superview viewWithTag:(textField.tag + 1)];
if (nextResponder) {
[nextResponder becomeFirstResponder];
// Your code for checking it.
}
return NO;
}
return YES;
}
Надеюсь, это поможет.
Swift 3,2
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let finalString: String? = (textField.text? as NSString).replacingCharacters(in: range, with: string)
if (finalString?.characters.count ?? 0) > 0 {
textField.text = string
let nextResponder: UIResponder? = textField.superview?.viewWithTag((textField.tag + 1))
if nextResponder != nil {
nextResponder?.becomeFirstResponder()
// Your code for checking it.
}
return false
}
return true
}
Swift 4.1
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let finalString: String? = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
if finalString?.count > 0 {
textField.text = string
let nextResponder: UIResponder? = textField.superview?.viewWithTag(textField.tag + 1)
if nextResponder != nil {
nextResponder?.becomeFirstResponder()
// Your code for checking it.
}
return false
}
return true
}