在 pickerview 文本字段上隐藏键盘

发布于 2024-12-20 12:59:28 字数 1118 浏览 2 评论 0原文

我已经实现了一个视图,其中有两个文本字段。在第一个文本字段中,当用户单击它时,会显示选择器视图。当用户单击其他文本字段时,会显示键盘。但是,当用户从第二个文本字段转到第一个文本字段时,它仍然显示键盘,并且该键盘的背面有一个选择器视图。当用户从第二个文本字段移动到第一个文本字段而不按键盘完成按钮时,我无法放弃此键盘。

 -(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;
     }

enter image description here

if some one has idea to dismiss the keyboard. Please provide the solution.

Thankyou very much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

深者入戏 2024-12-27 12:59:28

听起来您的问题的正确解决方案是将第一个文本字段的 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.

倒数 2024-12-27 12:59:28

在确定 firstTextField 处于活动状态后,尝试告诉 secondTextFieldresignFirstResponder

 -(void)textFieldDidBeginEditing:(UITextField *)myTextField
  {  
     if(myTextField == firsttextfield)
     {
        [firsttextfield resignFirstResponder];
        [secondtextfield resignFirstResponder];
        medicationtypepicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,190,320,215)];
        ....
      }
   }  

Try telling the secondTextField to also resignFirstResponder after you determine that firstTextField is active:

 -(void)textFieldDidBeginEditing:(UITextField *)myTextField
  {  
     if(myTextField == firsttextfield)
     {
        [firsttextfield resignFirstResponder];
        [secondtextfield resignFirstResponder];
        medicationtypepicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,190,320,215)];
        ....
      }
   }  
风筝有风,海豚有海 2024-12-27 12:59:28

检查您的文本字段的属性“退出时是否结束”是否与“文件所有者”正确连接。然后使用;
-(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];
.....
}
}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文