user609906
user609906

Reputation: 190

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 would be interested in your thoughts?

Thanks

Steve

Upvotes: 3

Views: 2076

Answers (4)

Fmessina
Fmessina

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

Matt Wilding
Matt Wilding

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

Thomas Clayson
Thomas Clayson

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

Max
Max

Reputation: 16709

You can try to send some control the message becomeFirstResponder

Upvotes: 0

Related Questions