Alessandro
Alessandro

Reputation: 4100

resignFirstResponder within child UIViewController

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

Answers (1)

Jogendar Choudhary
Jogendar Choudhary

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

Related Questions