Frederik Norlyk Eriksen Frederik Norlyk Eriksen - 1 month ago 9
Swift Question

Swift detect return key pressed without using textFieldDidEndEditing

Is there a way to detect that the return key was pressed on the keyboard without using

textFieldDidEndEditing
.
textFieldDidEndEditing
is also triggered if you for example perform a segue which dismisses the keyboard.

Answer

Below delegate is called when you press return key.

func textFieldShouldReturn(textField: UITextField) -> Bool {
    print("return pressed")
    textField.resignFirstResponder()
    return false
}
Comments