Search code examples
iosswiftiphoneipaduipickerview

Why does iPad does not dismiss picker view on end edit but iPhone does


I’ve set UIPickerView as input view of text field and on picker selection, I use view.endEditing(true). This closes keyboard on iPhone. But on iPad, nothing happens. I had to remove the picker view from super view by calling that method. What is the cause of this difference considering both are running same version of the OS?
Also are there any references to such differences so that I can use same method on both the devices.


Solution

  • The reason the keyboard is not getting dismissed is because some View will intercept these events, not because endEditing is not working.

    You can, nonetheless dismiss the keyboard globally, that might be an easy way out:

    UIApplication.shared.sendAction(#selector(UIResponder.resign‌​FirstResponder), to: nil, from: nil, for: nil)
    

    You have a nice day!