Reputation: 4100
I am adding several view controllers to the main view controller by doing
addChildViewController(viewController)
viewController.didMove(toParentViewController: self)
Everything works fine, the only problem is that within my methods for the UITextFieldDelegate, the resignFirstResponder()
and becomeFirstResponder()
do not work. If I do sender.resignFirstResponder()
in an @IBAction
for example, the function executes, but I can't dismiss the keyboard. Any ideas?
EDIT:
self.view.endEditing(true)
also doesn't work
Upvotes: 0
Views: 169
Reputation: 3494
Please try this, this will work for you:
self.view.endEditing(true)
OR add this in viewDidAppear:
override func viewDidAppear(_ animated: Bool) {
self.view.endEditing(true)
}
Upvotes: 1