iOS UITextField Delegate Find Next Tag & Manage Keyboard

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

The text field calls different delegate methods (only if delegates are set)One of delegate method called by textfield is *- (BOOL)textFieldShouldReturn:(UITextField )textField

This method is called whenever users taps the return button.By using this method, we can implement any custom behaviour.

For Example,

In the below example ,next responder will be find out on the basis of tag and manage the keyboard. Here 20 is the constant,As tag assigned to textfield are like this 50,70,90 etc.

Here on finding a new textfield object as responder,it will make current text field as new responder and open keyboard accordingly.

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


Got any iOS Question?