Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>That's pretty simple. First of all, set your textFields with tag in a ascending way, like this. And also, set it's delegates to self:</p> <pre><code>//set up this somewhere self.nameTextField.tag = 0; self.nameTextField.delegate = self; self.emailTextField.tag = 1; self.emailTextField.delegate = self; self.passwordTextField.tag = 2; self.passwordTextField.delegate = self; </code></pre> <p>And then, implement the <code>UITextField</code> delegate's method <code>textFieldShouldReturn:</code> like below. Don't forget to add the <code>UITextFieldDelegate</code> in your .h file:</p> <p>In your <code>ViewController.h</code> file:</p> <pre><code>@interface ViewController : UIViewController &lt;UITextFieldDelegate&gt; </code></pre> <p>And in your <code>ViewController.m</code> file:</p> <pre><code>- (BOOL)textFieldShouldReturn:(UITextField *)textField { NSUInteger index = textField.tag; if (index == 2) { // Last textField [textField resignFirstResponder]; }else{ UITextField *nextTextField = (UITextField*)[self.view viewWithTag:index+1]; [nextTextField becomeFirstResponder]; } return NO; } </code></pre> <p>This should answer your main question. And for the side question, that's simple too. You just have to add a <code>UIGestureRecognizer</code> to your view, calling a method that resigns the firstResponder to the selected <code>UITextField</code>. It will be something like this:</p> <p>Set-up the gesture recognizer somewhere, like in your <code>viewDidLoad</code> method</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; UITapGestureRecognizer *dismissKeyboard = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)]; [self.view addGestureRecognizer:dismissKeyboard]; } </code></pre> <p>And implement the method that performs the dismiss, like this:</p> <pre><code>- (void)dismissKeyboard { [self.view endEditing:YES]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload