resignFirstResponder and close keyboard from anywhere?
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 wou开发者_StackOverflow中文版ld be interested in your thoughts?
Thanks
Steve
To dismiss the keyboard from anywhere, even if you don't know directly who is the firstResponder, use:
[[[[UIApplication sharedApplication] delegate] window] endEditing:YES];
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.
You can try to send some control the message becomeFirstResponder
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];
}
精彩评论