title: Switch between UITextFields when return button is pressed
body: <p>Im trying to have my UITextFields switch to the next one when the return button is pressed. Here Is my code: </p>
  
  <pre><code>func textFieldShouldReturn(_ textField: UITextField) -&gt; Bool
      {
          // Try to find next responder
          if let nextField = textField.superview?.superview?.viewWithTag(textField.tag + 1) as? UITextField {
              nextField.becomeFirstResponder()
              print("success")
          } else { //if textField.text != nil {
              textField.resignFirstResponder()
              print("error")
      } 
      return false
  }
  </code></pre>
  
  <p>I use this code all the time with other projects. However, this is an exception. I have each element in it's own stack view, and all of those stack views are in a superview stack view. Once I run the app, I press the return button and it goes to the else statement and resigns the first responder. I need it to run the <code>nextField.becomesFirstResponder()</code>
  <a href="https://i.stack.imgur.com/QPwQV.png" rel="nofollow noreferrer">Here is a screenshot</a></p>