UITextView doesn't switch input toolbar to custom keyboard

755 Views Asked by At

iOS9 Xcode7 beta6: I'm trying to switch between keyboards (custom/default) for UITextView by using reloadInputViews(). Changing UIKeyboardType and UIKeyboardAppearance by calling reloadInputViews() works perfectly. Also following code works well under iOS8.

This implies that textView is already a first responder:

private func showCustomKeyboard() {
    textView.inputView = customKeyboardView
    textView.reloadInputViews()
}

private func showDefaultKeyboard() {
    textView.inputView = nil
    textView.reloadInputViews()
}

Things like the following have made no effect and also they look like overkill:

textView.inputView.resignFirstResponder()
textView.inputView.becomeFirstResponder()
textView.inputView = customKeyboardView
textView.reloadInputViews()

I found a couple of related questions on SO but no one of them doesn't have to do with iOS9 and as I said before it does work in iOS8.

Have anyone come across this bug?

2

There are 2 best solutions below

0
On BEST ANSWER

The bug was related to a simulator with iOS9 on the board and eventually has been fixed with unchecking Keyboard -> Connect -> Hardware Keyboard.

3
On

Did you try to change the order? Because you dismiss and after that show a keyboard again. Does it make sense?:

textView?.inputView.resignFirstResponder() // dismiss keyboard
textView?.inputView.becomeFirstResponder() // show keyboard
textView?.inputView = customKeyboardView // reassign new keyboard
textView?.reloadInputViews() // reload keyboard

Try:

textView?.inputView.resignFirstResponder() // dismiss keyboard
textView?.inputView = customKeyboardView // reassign new keyboard
textView?.reloadInputViews() // reload keyboard
textView?.inputView.becomeFirstResponder() // show keyboard