在 pickerview 文本字段上隐藏键盘
我已经实现了一个视图,其中有两个文本字段。在第一个文本字段中,当用户单击它时,会显示选择器视图。当用户单击其他文本字段时,会显示键盘。但是,当用户从第二个文本字段转到第一个文本字段时,它仍然显示键盘,并且该键盘的背面有一个选择器视图。当用户从第二个文本字段移动到第一个文本字段而不按键盘完成按钮时,我无法放弃此键盘。
-(void)textFieldDidBeginEditing:(UITextField *)myTextField
{
if(myTextField == firsttextfield)
{
[firsttextfield resignFirstResponder];
medicationtypepicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,190,320,215)];
medicinetypearray = [[NSMutableArray alloc]initWithObjects:@"Capsules",@"Eyedrops",
@"Eardrops",@"Nosedrops",@"Inhaler",@"Syrup",@"Injections",@"Oils",@"Ointment", nil];
medicationtypepicker.delegate = self;
medicationtypepicker.showsSelectionIndicator = YES;
medicationtypepicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:medicationtypepicker];
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[secondtextfield resignFirstResponder];
return YES;
}
如果有人想关闭键盘。请提供解决方案。
非常感谢。
I have implemented a view, in which there is two text fields. At first text field, when user click on it, there is a display of picker view. When user clicks on other text field keyboard is shown. But when user go from second text field to first text field it still shows the keyboard and there is a picker view on the back of this keyboard. I am unable to resign this keyboard when user move from second to first textfield without pressing keyboard done button.
-(void)textFieldDidBeginEditing:(UITextField *)myTextField
{
if(myTextField == firsttextfield)
{
[firsttextfield resignFirstResponder];
medicationtypepicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,190,320,215)];
medicinetypearray = [[NSMutableArray alloc]initWithObjects:@"Capsules",@"Eyedrops",
@"Eardrops",@"Nosedrops",@"Inhaler",@"Syrup",@"Injections",@"Oils",@"Ointment", nil];
medicationtypepicker.delegate = self;
medicationtypepicker.showsSelectionIndicator = YES;
medicationtypepicker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:medicationtypepicker];
}
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[secondtextfield resignFirstResponder];
return YES;
}
if some one has idea to dismiss the keyboard. Please provide the solution.
Thankyou very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您的问题的正确解决方案是将第一个文本字段的
inputView
属性设置为选择器视图。让您的视图控制器在显示“药物详细信息”屏幕时创建并配置选择器,并将该选择器分配给第一个文本字段的
inputView
。然后,当用户从一个字段移动到另一个字段时,键盘或选择器将自动显示,而您不必浪费时间辞职第一响应者等等。It sounds like the right solution for your problem is to set the first text field's
inputView
property to the picker view.Have your view controller create and configure the picker when the Medication Details screen is presented, and assign that picker to the first text field's
inputView
. Then, as the user moves from one field to another, the keyboard or picker will automatically be displayed without you having to fool around with resigning first responder and so forth.在确定
firstTextField
处于活动状态后,尝试告诉secondTextField
也resignFirstResponder
:Try telling the
secondTextField
to alsoresignFirstResponder
after you determine thatfirstTextField
is active:检查您的文本字段的属性“退出时是否结束”是否与“文件所有者”正确连接。然后使用;
-(void)textFieldDidBeginEditing:(UITextField *)myTextField
{
if(myTextField == 第一个文本字段)
{
...
[第二个文本字段辞职第一响应者];
……
}
}
check out that your text field's property " Did End on Exit" is connected with the 'Files Owner' proerly. Then use;
-(void)textFieldDidBeginEditing:(UITextField *)myTextField
{
if(myTextField == firsttextfield)
{
...
[secondtextfield resignFirstResponder];
.....
}
}