I have an application with Textfields in my MainViewController.m file. There is also a scrollview in that file, so when the keyboard comes up, the view scrolls so the user can see the textfield. The keyboard is dismissed when the user taps on the screen. Everything is working well EXCEPT in the case that the user hits the home button to put the app in the background and then comes back to it. In this case, the keyboard is still up, but my scrollview is down with textfields hidden. Ideally I would like to have the keyboard be dismissed as well.
Having looked into it, the methods that are called are all in the AppDelegate.m file (unfortunately it does not go into ViewDidLoad or any of the View lifecycle methods). How do I dismiss the keyboard from applicationDidEnterBackground in the AppDelegate.m file?
I am kind of a newbie – I have tried making a +dismisskeyboard function in my MainViewController file and calling it from the Appdelegate, but my Textfields are all instance variables and that does not work. I have also tried to create a textfield in my AppDelegate file and then do this –
[_someField becomeFirstResponder];
[_someField resignFirstResponder];
but this also does not work… I can’t figure out how to link anything on my storyboard to the AppDelegate property of someField.
Can anyone suggest the correct approach to tackle this problem?
Just register a method for
UIApplicationDidEnterBackgroundNotificationin yourMainViewControllerclass and dismiss your keyboard there. e.g.Register for the notification
then add this method