如何在文字字段iOS上点击时出现键盘? [英] How to disable keyboard appearing when hitting on a text field , iOS?
问题描述
我有一个文本字段,当用户按下它以显示自定义选择器时我需要。
I have a text field , and i need when the user presses it to show a custom picker.
选择器显示正常,但问题是键盘出现在底部,我不想要那个。
The picker is shown fine , but the problem is that the keyboard appears on the bottom and i dont want that.
这是一个iPad项目,我试图从我的iPhone转换。在iPhone上,这很好用,键盘总是隐藏的。
This is an iPad project which i am trying to convert from my iphone one. On the iPhone , this works well and the keyboard is always hidden.
我有什么遗失/忘记在这里做什么?
What could i be missing/forgetting to do here ?
为了将来参考这里实际发生的事情,实际上两次都是这样的(iphone& ipad)键盘不隐藏。我只是觉得它隐藏在iPhone中,因为从底部弹出的拾取器隐藏了键盘,因为它位于它的顶部。但在ipad上并非如此。
For future reference what actually happened here , was that in fact both times (iphone & ipad) the keyboard was not hidden. I just thought that it was hidden in the iphone because my picker , which was popping from the bottom was hiding the keyboard as it was on top of it. But on ipad this wasnt the case.
无论如何我使用下面建议的委托方法修复它。
Anyway i fixed it , using the delegate method suggested below.
小心,我接受了这个答案,因为这是一个回答 特别 我想要的人。其余的答案是正确的,我认为其他实现更好。
Caution , i accepted this answer cause it was the one answering specifically what i wanted. The rest of the answers are correct and my considered better for other implementations.
推荐答案
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
// Here You can do additional code or task instead of writing with keyboard
return NO;
}
当您点击文本字段并且写入时,将首先调用此deleagate方法NO作为布尔值意味着您不想开始编辑,因此它不会显示键盘。
this deleagate method will get called first when you hit to textfield and if you write NO as a boolean value means you dont want to begin editing so it will not present Keyboard.
这篇关于如何在文字字段iOS上点击时出现键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!