单击 UITextField 时,选择器出现,但 kwyboard 没有消失
我有一个包含 10 个单元格的表格视图,每个单元格都有一个文本字段。直到文本字段 5,我希望用户使用键盘输入一些值。在文本字段 6 上,我希望用户从列表中选择值(显示选择器视图)。 发生的情况是,当我单击字段 5(显示键盘),输入一些值,然后按返回按钮(键盘上),键盘按下,然后单击文本字段 6(显示选择器),显示选择器(此处没有键盘出现)。
但是如果我不按键盘的返回按钮(在字段5上)并直接单击字段6(选择器),那么我的选择器会出现,键盘位于顶部,也就是说,键盘不会下降,选择器会出现在键盘后面。在这里,当我单击键盘返回时,键盘也不会下降。要使键盘按下,我需要单击任何文本字段(显示键盘),然后按回车键。
有人遇到过这个奇怪的问题吗?请帮帮我。
I have a table view containing 10 cells and each cell has a text field. Till textfield 5, I want the user to enter some value using keyboard. On text field 6, I want the user to select values from a list (showing picker view).
What is happening is when I click on field 5 (showing keyboard), entered some value and then hit return button (on keyboard), the keyboard goes down and then, I click on text field 6 (showing picker), the picker is shown (no keyboard appears here).
BUT if I dont hit return button of keyboard (on field 5) and directly click on field 6 (picker), then my picker appears with the keyboard at the top, that is, keyboard doesn't goes down and picker appears behind the keyboard. Here, when I click on return of keyboard, then also keyboard doesn't goes down. To make the keyboard go down, I need to click on any text field (showing keyboard) and then hit return.
Has anybody faced this strange problem?? Please help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须设置每个文本字段的标签并设置委托,然后像这样放置此委托方法,
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
如果(textField.tag == 6)
<前><代码>{
[textField resignFirstResponder];
}
返回是;
}
享受!
you have to set the tag of each textfield and set the delegate and then put this delegate method like this,
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
If (textField.tag == 6)
return YES;
}
Enjoy!
不要手动将选择器添加为子视图。将其设置为文本字段的
inputView
(在cellForRowAtIndexPath
上),操作系统将为您负责显示和隐藏。Dont add the picker as a subview manually. Set it as the
inputView
of the text field (oncellForRowAtIndexPath
) and the OS will take care of showing and hiding for you.