How to dismiss already open keyboard when ios popover appears

In my iOS project, I have a form that contains various text boxes. Some text fields are editable with the keyboard, and some with selection mode, which is placed in the popover.

When I keep filling the text boxes without releasing them, and then if I press down on the keyboard, the text of the box stays open.

It seems that both the keyboard and the popover are present on the screen at the same time, which is not what I want.

I can get if the keyboard is open or not by setting a flag in the keyboard notification methods as well as the last text that was edited with the text delegates passed in. And tried

  • [self endEditing: YES]; (as in a table cell)

  • [lastEditedTextField resignFirstResponder];

Even try to pass the keyboard with self notification (not knowing if this is possible or not)

  1. [[NSNotificationCenter defaultCenter] postNotificationName: UIKeyboardWillHideNotification object: nil];

but nothing works.

How can I remove the keyboard (if it is already open) when the popover appears.

Thanks in advance.

+3


source to share


2 answers


Try to implement textFieldShouldBeginEditing:

and inside it check which textbox it is. If it is one of the fields that the popover should display, first call [self.view endEditing:YES]

to hide the keyboard, then specify the popover and return NO

. This way the textbox will not accept the first responder status and the keyboard will no longer appear. And if it's one of the "normal" text fields, just return YES

.



+1


source


You may call:

[self.view endEditing:YES];

      



But the best solution is likely to be presented by the collector, using UIResponder

inputView

so that it automatically replaces the keyboard and you don't need to be notified of two different things (and the user doesn't potentially switch between different parts of the screen).

+2


source







All Articles