0

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?

Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37

2 Answers2

2

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
Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37
Vitalii Gozhenko
  • 9,220
  • 2
  • 48
  • 66
  • It doesn't make sense because reloadInputViews should be called while an object is a first responder. In all my examples I imply that a textView is already a first responder. – Dmytro Hutsuliak Sep 02 '15 at 08:15
  • Tell me a reason to make `resignFirstResponder` and `becomeFirstResponder` after that? – Vitalii Gozhenko Sep 03 '15 at 19:47
  • The reason is to force reloading of textView properties and it helps in some cases as you can see here: http://stackoverflow.com/questions/24546339/uitextfield-no-longer-reloads-keyboardtype-after-reloadinputviews-call/26066823#26066823 In your example Apple's documentation says the following about reloadInputViews: "If the current object is not the first responder, this method has no effect." unfortunately. – Dmytro Hutsuliak Sep 03 '15 at 20:03
0

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

Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37