0

I have a login view that I want to automatically submit when the user presses enter. There are two fields, username and password and a login UIButton which "submits" the form. All work fine, however I want the form to submit when the user press enter also.

I have seen Xcode set default button on enter when making a form but it is for Obj-c and the accepted answer which is "You set the Key Equivalent value for your button in IB. Just click on that field in the attributes inspector and press the enter key." is apparently for an older version of Xcode as I can't find a "Key Equivalent" field in the attributes inspector for the button or enclosing views.

Please show me how in either IB or swift 2 code.

Thanks in advance.

Community
  • 1
  • 1
TBone
  • 11
  • 1
  • The question you linked to is for Mac OS. I don't believe this feature exists for iOS. I'm guessing you want the login form to submit when the enter key is pressed. I would suggest looking at http://stackoverflow.com/questions/5963138/ios-action-with-enter-key-of-ipad-keyboard – BergQuester Jan 14 '16 at 20:57

1 Answers1

0

You can use the textFieldShouldReturn delegate method to detect when the return/enter button is pressed on the keyboard.

func textFieldShouldReturn(textField: UITextField!) -> Bool {
    if textField == passwordTextField {
        textField.resignFirstResponder() // close keyboard
        login()
    }
    return YES
}
Beau Nouvelle
  • 6,962
  • 3
  • 39
  • 54