xcode 使用inputView后如何显示键盘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11696419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to show keyboard after used inputView
提问by Pavel Kaljunen
I used inputView
to show uipickerview
for my textfield
, but I use same textfield
for other functions. How can I show standard keyboard after I used inputView
for that textfield
?
我曾经为我的inputView
显示,但我对其他功能使用相同的。我如何能显示标准键盘我用后为?uipickerview
textfield
textfield
inputView
textfield
textfield.inputView = pickrView;
回答by Pavel Kaljunen
Just
只是
textfield.inputView = nil;
textfield.inputView = nil;
worked for me
对我来说有效
回答by MPajak
As Pavel Kaljunen said, you need only to set the inputView to nil, but when the keyboard is already visible, you have to resignFirstResponder first, set the inputView to nil and then becomeFirstResponder again.
正如Pavel Kaljunen所说,你只需要将inputView设置为nil,但是当键盘已经可见时,你必须先resignFirstResponder,将inputView设置为nil,然后再次成为FirstResponder。
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.35];
[yourTextField resignFirstResponder];
yourTextField.inputView = nil;
[yourTextField becomeFirstResponder];
[UIView commitAnimations];
回答by cloosen
i think this code maybe can work
我认为这段代码也许可以工作
[textField.inputView addTarget:self action:@selector(doTest) forControlEvents:UIControlEventTouchUpInside];
- (void)doTest
{
if([textFiled isFirstResponder])
{
[textFiled resignFirstResponder];
}
else
{
[textFiled becomeFirstResponder];
}
}