Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing keyboard from Screen without calling resignFirstResponder

I have a custom View (NotifyView) added on UIWindow with a dismiss button(which remove it from UIWindow). This view is added when a PUSH notification comes in didReceiveRemoteNotification there are several cases when I could be on any screen, and my keyboard is UP via UITextfield/UITextview. At this stage if a push comes, the NotifyView is added on UIWindow behind the keyboard. I want to resign the keyboard once the PUSH is received so for that I could:

  • post a Notification with NSNotificaitonCenter to resign all textfields/textviews (if anyone is firstResponder). For this I have to keep active pointer to the currently active textfield/textview in all controllers.

  • make a variable in AppDelegate and assign the active textfields/textviews to it and on PUSH, and resignFirstResponder of those on PUSH.

Both of the solutions would require making changes to all controller's code and I am looking for something more generic like:

  • could there be any way through which I could simply remove the Keyboard from the screen on receiving PUSH
  • or I could fetch the current firstResponder of the application and resign it explicitly.

these could be generic solutions.

It would be really helpful if someone could facilitate this thought process or someone have any immediate solution for this case.

like image 954
Saurabh Passolia Avatar asked Apr 26 '13 08:04

Saurabh Passolia


2 Answers

You can use the method below

[[[UIApplication sharedApplication] keyWindow] endEditing:YES]
like image 61
vignesh kumar Avatar answered Oct 24 '22 11:10

vignesh kumar


Try this one , for me it works fine [yourView endEditing:YES]

like image 39
taffarel Avatar answered Oct 24 '22 10:10

taffarel