Switching between Text fields on pressing return key in Swift

前端 未结 15 1440
名媛妹妹
名媛妹妹 2020-12-04 09:25

I\'m designing an iOS app and I want that when the return key is pressed in my iPhone it directs me to the next following text field.

I have found a couple of similar

15条回答
  •  抹茶落季
    2020-12-04 09:56

    I have a good solution for your question.

    STEP:

    1 - Set your return key from the storyboard.

    2 - In your swift file.

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
            if textField.returnKeyType == .next {
                Email.resignFirstResponder()
                Password.becomeFirstResponder()
            } else if textField.returnKeyType == .go {
                Password.resignFirstResponder()
                self.Login_Action()
            }
            return true
        }
    

    3 - Don't forget to set the delegate of the Textfield.

    Thank you :)

提交回复
热议问题