The following code used to work in iOS6 to hide the keyboard when a view controller was popped off of the navigation stack:
- (void)viewWillDisappear:(BOOL)animated {
[self.view endEditing:YES];
[super viewWillDisappear:animated];
}
However, in iOS7, the [self.view endEditing:YES] line seems to get ignored. I tried the command in other view events (viewDidDisappear, viewWillAppear, and viewDidAppear), and the only one it worked in is viewDidAppear. It seems that once a "pop" is initiated, we lose the ability to hide the keyboard until the view controller is "pushed" back on the stack.
While placing the code in viewDidAppear does work to hide the keyboard, the bad thing is that the keyboard is displayed briefly when the viewController is pushed back on to the navigation stack...pretty unacceptable from a UI perspective.
Has anyone else had success in working around this issue? I would prefer not to have to write my own CANCEL button, but right now, that is the only thing I can think of that will work.
If it's a UITextView
set the editable
property to NO
. I tried this and it hides the keyboard as soon as it's set. I haven't tried it with a UITextField
but I'm guessing you'd get the same result with setting the enabled
property to NO
. If that doesn't work, create a UITextField
with userInteractionEnabled
set to NO
as a background for a transparent UITextView
and use the editable
property as stated above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With