Popover view won't close keyboard

I have a popover view containing a tableview, and inside of the tableview are various UITextFields.

If one of the text fields is selected and the keyboard is showing, and I swipe downwards on the popover view, the popover closes, but the keyboard remains visible.

I updated my viewWillDisappear method on the view controller to have it issue a resignFirstResponder to the active input view when the popover closes, and although this code gets called, it doesn't close the keyboard.

The problem only exists on an iPhone. When I run the same code on an iPad, it works as expected (tapping outside of the popover view closes both the view and the keyboard).

If I dismiss the popover myself after issuing resignFirstResponder, that works. It is only the case where the user swipes down to dismiss that the problem appears.

Answered by Claude31 in 748815022

You could try this:

  • keep a reference to the TextField when you select it, in a var in the ViewController
var activeTextField : UITextField?
  • in viewWillDisappear, call resignFirstResponder on this reference
activeTextField?.resignFirstResponder()

It is only the case where the user swipes down to dismiss that the problem appears : what do you swipe down ? The popover ?

Basically I'm swiping down from the top edge of the view. This is the only time I see the problem. If I close the view by calling dismiss myself (for example if I put a cancel button in the view), it works fine. I don't really need or care about the swipe-to-close behavior. Can it be disabled?

Accepted Answer

You could try this:

  • keep a reference to the TextField when you select it, in a var in the ViewController
var activeTextField : UITextField?
  • in viewWillDisappear, call resignFirstResponder on this reference
activeTextField?.resignFirstResponder()
Popover view won't close keyboard
 
 
Q