I have seen this question, but the question is how to know which textView is the first responder? This question looked promising to figure out the first responder, but it turns out that it calls private APIs. Is there any way to hide the keyboard or to figure out the first responder as the-one-who-has-the-keyboard?
It's easy:
[[[UIApplication sharedApplication] keyWindow] endEditing:YES];
take a look at UIView Class Reference.
[textView isFirstResponder]
should tell you if it's the first responder. I guess you could just loop through all text fields in your class to check if it's the first responder.
Or you could just call resignFirstResponder on every textField, and it'll still work.
I believe you should pick something to become the first responder, something which probably doesn't do anything on its own, and call -[UIResponder becomeFirstResponder]
on it. This would work well with a UIViewController or UIWindow (which you can get through -[UIView window]
, I think) because these would have the most similar responder chains, and would make the current firstResponder loose its firstResponder status, dismissing the keyboard, but also wouldn't bring up the keyboard, as it would not be a UITextField.
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