views:

19

answers:

1

Loading a custom input view into a UITextField, I can arbitrarily change the keyboard type of the standard keyboard between UIKeyboardTypeAlphabet and UIKeyboardTypeNumberPad. Just call something like:

[editingField setKeyboardType:UIKeyboardTypeNumberPad];
[editingField reloadInputViews];

And viola! There is your number pad.

Without changing this block of code, but just making editingField a UITextView instead of a UITextField, it no longer works. According to the docs, these are both compliant with the UITextInput and UITextInputTraits protocols.

It is worth mentioning that the above code actually does work, but only after the user leaves the textView in question and later reselects it. It is almost like reloadInputViews does nothing, and then the textView loads its input views when it becomeFirstResponder.

I have tried all sorts of performSelector: etc and cannot force the issue. Any ideas? How do you make UITextView obey reloadInputViews and dynamically change its inputView?

A: 

Are you setting inputView of UITextView to nil before calling?

[editingField setKeyboardType:UIKeyboardTypeNumberPad];
[editingField reloadInputViews];
Deniz Mert Edincik
Hi, yes I call [editingField setInputView:nil]; before setting the type.
SG1
tf.inputView = nil;[tf resignFirstResponder];[tf setKeyboardType:UIKeyboardTypeEmailAddress];[tf becomeFirstResponder];[tf reloadInputViews]; sequence works. But I will check for this strange behavior in my free time, and let you know if I find anything.
Deniz Mert Edincik
Hi, I tried this before, thinking the same thing. Doing resignFirstResponder and then becomeFirstResponder in rapid succession doesn't seem to work: the textView just resigns and stays that way.
SG1
Just inspected SDK, and UITextView updates keyboard on becomeFirstResponder, I just tried on simulator, it works with (set inputView to nil, resignFR, setkeyboard, becomeFR). Also I guess reloadInputViews is not necessary in this approach.
Deniz Mert Edincik
OK, apparently declaring it as a UITextView instead of a UIResponder affects how it behaves during runtime. That is literally the only change I made and it works now. Thanks.
SG1