Search code examples
swiftuitextfieldios9resignfirstresponder

How to resignFirstResponder from a View but when app goes to background state in Swift?


Hy guys I am having problems with all UITextFields within my app that when it is as firstResponder and then I go to background and come back when I edit the characters alternatively shows/disappear.

I read some posts here on StackOverflow and people say that it is because before going to background state the UITextField was firstResponder and it should not be.

So the problem is that I can´t figure out how I would code to resignFirstResponder when user clicks the Home button.

Anyone could help?


Solution

  • I got it fixed by adding this code to AppDelegate:

    func applicationWillResignActive(application: UIApplication) {
        window?.endEditing(true)
    }