03Find Next Tag Manage Keyboard

suggest change

The 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;
           }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents