I happening the following problem:
I have two TextField, one has the default behavior, and on the other, captures the textFieldDidBeginEditing method delegate, to present a UIViewController with PresentationStyle (Custom) and TransitionStyle (CrossDissolve). So far everything works fine. But if I edit the first textField (and leave the keyboard open) and then go to the second, the keyboard is open and I have no way to close it (as if the first textField had lost focus, not even the textFieldShouldReturn is called when I press the button intro).
I tried with:
- TextFieldDidEndEditing (for calling resignFirstResponder)
In viewWillDissaper method (I also called resignFirstResponder)
func textFieldShouldReturn(textField: UITextField) -> Bool { textField.resignFirstResponder() return true } func textFieldDidEndEditing(textField: UITextField) { print("Resign Last TextField") textField.resignFirstResponder() } func textFieldDidBeginEditing(textField: UITextField) { print("Did Begin editing") if textField == self.departing || textField == self.returning{ textField.resignFirstResponder() self.lastTextFieldSelected = textField let datePickerViewController = Util.getViewController("DatePickerViewController") as! DatePickerViewController datePickerViewController.dateStyle = NSDateFormatterStyle.ShortStyle datePickerViewController.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve datePickerViewController.modalPresentationStyle = UIModalPresentationStyle.Custom datePickerViewController.datePickerDelegate = self self.presentViewController(datePickerViewController, animated: true, completion: nil) } }
Edit: I try with self.view.endEditing(true) nothing.
I made a little example (something I check, is that textFieldShouldBeginEditing allows me to close the keyboard.): https://github.com/Abreu0101/TextFieldBug
textFieldDidBeginEditingcode actually executing? - mattself.view.endEditing = true- tuledev