Reputation: 190
I have a situation where the keyboard maybe open and then an NSTimer pops a view over the text view. Is there anyway to close the keyboard globally rather than from the text view resignFirstResponder method? The reason I ask is that the textView is dynamic in that it maybe there sometimes and not others. One way would be to give it a TAG. Can multiple items be referenced with same tag?
I think the answer is no but I would be interested in your thoughts?
Thanks
Steve
Upvotes: 3
Views: 2076
Reputation: 3771
To dismiss the keyboard from anywhere, even if you don't know directly who is the firstResponder, use:
[[[[UIApplication sharedApplication] delegate] window] endEditing:YES];
Upvotes: 7
Reputation: 20153
The endEditing: method of UIView should do the trick. Send it to the superview of the potentially existing UITextView when you want to dismiss the keyboard.
Upvotes: 5
Reputation: 29925
You could pass a reference to the UITextView in the NSTimer...
ORRRRR....
In the view that pops up you could do something like:
for(id view in self.superview.subviews){
[(UIView *)view resignFirstResponder];
}
Upvotes: 0