03Find Next Tag Manage Keyboard
suggest changeThe text field calls different delegate methods only if its delegate is set. One of those methods is - (BOOL)textFieldShouldReturn:(UITextField *)textField.
This method is called whenever the user taps the return button. By using this method, we can implement any custom behaviour.
For example, the next responder is chosen from the tag, and the keyboard is managed that way. Here 20 is the step between tags, because the text fields are tagged 50, 70, 90, and so on.
When a next text field is found, it becomes first responder and the keyboard stays up for that field.
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSInteger nextTag = textField.tag+20;
// Try to find next responder
UIResponder *nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder)
{
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
}
else
{
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return YES;
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents