在reloadInputViews调用之后,UITextField不再重新加载keyboardType [英] UITextField no longer reloads keyboardType after reloadInputViews call
问题描述
在iOS 7中,我可以更改键盘类型,而它是 firstResponder
(即时):
In iOS 7, I could change the keyboard type while it is the firstResponder
(on the fly):
if (textField.text.length > 2) {
textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
}
else
{
textField.keyboardType = UIKeyboardTypeDefault;
}
[textField reloadInputViews];
// (Omitting some efficiency stuff to keep example to bare bones)
这在Xcode 6 / iOS 8下不再有效。文档主要反映了有关自定义键盘的更改。
This no longer works under Xcode 6/iOS 8. The documentations mostly reflect changes regarding custom keyboard.
使用resign /成为第一响应者是(仍然)工作:
Using resign/become first responder is (still) working:
[textField resignFirstResponder];
// Make keyboard change
[textField becomeFirstResponder];
但这只是一种矫枉过正的感觉。它正在撕裂并重建墙壁,只是为了更改它上面的图片。
But it just feels like an overkill. It's tearing and rebuilding a wall, just to change a picture on it.
这里有一个相关的帖子:
UITextView似乎没有实现reloadInputViews
There is a related post here: UITextView does not seem to implement reloadInputViews
但是似乎解决方案(在评论中)是显然将其声明为UITextView而不是UIResponder会影响它在运行时的行为方式....现在它可以正常工作
But it seems that the solution (in a comment) is "apparently declaring it as a UITextView instead of a UIResponder affects how it behaves during runtime. ... and it works now"
在我的情况下,是一个 UITextField
,我试图转换为 UITextView
以防万一。不行。
In my case it is a UITextField
, and I tried to cast to UITextView
just in case. No go.
我再次提到 在iOS7 / Xcode5下运行良好。
I'll mention again that it is working well under iOS7 / Xcode5.
我真的不知道这是Xcode 6的'beta'问题,还是iOS 8中的设计更改。
I don't really know if this is a 'beta' issue with Xcode 6, or a design change in iOS 8.
推荐答案
我发现了同样的问题。最好检查textField是否已经是firstResponder。
I found the same issue. It is better to check whether the textField is already the firstResponder or not.
[textField reloadInputViews]; // does not work on iOS8 !
if ([textField isFirstResponder]) {
[textField resignFirstResponder];
[textField becomeFirstResponder];
}
虽然不是很干净但是有效。
Not a clean way though, but it works.
这篇关于在reloadInputViews调用之后,UITextField不再重新加载keyboardType的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!