Removing the keyboard from the screen without calling resignFirstResponder

I have a custom view ( NotifyView ) added to UIWindow with a dismiss button (which removes it from UIWindow ). This view is added when the PUSH notification comes in didReceiveRemoteNotification there are several cases where I could be on any screen, and my keyboard is UP via UITextfield / UITextview . At this point, if a click occurs, NotifyView added to the UIWindow behind the keyboard. I want to cancel the keyboard after receiving PUSH so that I can:

  • publish the notification using NSNotificaitonCenter to cancel all text fields / text fields (if there is firstResponder ). To do this, I have to keep an active pointer to the current active text field / text in all controllers.

  • make a variable in AppDelegate and assign active text fields / text fields to it, as well as PUSH and resignFirstResponder those located on PUSH.

Both solutions will require changes to all controller codes, and I'm looking for something more general, for example:

  • there may be some way through which I could just remove the Keyboard from the screen when receiving PUSH
  • or I could get the current firstResponder of the application and explicitly abandon it.

these may be general solutions.

It would be very helpful if someone could facilitate this process of thought, or someone has an immediate solution for this case.

+7
source share
4 answers

You can use the method below

 [[[UIApplication sharedApplication] keyWindow] endEditing:YES] 
+6
source

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

+4
source

The problem is that you want to return focus.

I implemented as listening to each text box and caching which is the last. Then cancel only one (after pressing) after this recovery state, this will require focus.

0
source

Try this in the delegate method ...

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { [self.view endEditing:YES]; // added this in for case when keyboard was already on screen [self editStartDate:textField]; return NO; } 
0
source

All Articles