Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 225
Developer Avatar asked Oct 28 '16 07:10

Developer


1 Answers

The below delegate is called when you press the return key.

func textFieldShouldReturn(textField: UITextField) -> Bool {
    print("return pressed")
    textField.resignFirstResponder()
    return false
}
like image 56
Annie Gupta Avatar answered Dec 23 '22 12:12

Annie Gupta