【问题标题】:How can I make the keyboard of other text field disappear while accessing other text field访问其他文本字段时如何使其他文本字段的键盘消失
【发布时间】:2012-03-20 05:51:27
【问题描述】:

我的视图中有两个文本字段。我是用 IB 做的。在第二个文本字段中,我正在使用操作表

在 textField1 中输入文本后,我在文本 Field-2 中。在第二个文本字段中,我使用带有选择器的操作表来选择日期。所以我在打开操作表之前退出了 textfield -2 键盘。在我试图退出键盘时关闭操作表后,它没有返回。 我用过

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textfield1 resignFirstResponder];
    return YES;
}  

辞职 textfield1 ..

【问题讨论】:

    标签: iphone objective-c ios uitextfield uikeyboard


    【解决方案1】:
    - (void) viewDidLoad
    {
       //don't forget to add <UITextFieldDelegate> in your .h
       firstTextField.delegate=self;
       secondTextField.delegate=self;
    }
    
    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        if(textField.tag==2)
        {
          //Here you can call function to view your datepicker
          return NO; //Will not open keyboard for second textfield.
        }
        return YES;
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        [textField resignFirstResponder];
        return YES;
    }
    

    【讨论】:

      【解决方案2】:

      你已经返回当前的 textField textFieldShouldReturn 方法改变你的 textFieldShouldReturn 方法,如下所示

      - (BOOL)textFieldShouldReturn:(UITextField *)textField{
          [textField resignFirstResponder];
          return YES;
      }
      

      【讨论】:

        【解决方案3】:

        你需要给TextField的标签,

        在这个方法中,

        - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
        {              
            if (textField.tag == 2)
            {
               [textField1 resignFirstResponder];
               // your action sheet code here 
            } 
        }
        
        - (BOOL)textFieldShouldReturn:(UITextField *)textField           
        {
           [textfield resignFirstResponder]
           return YES;
        }  
        

        【讨论】:

        • 在不返回第一个文本字段键盘的情况下,我将传递给第二个。第二个字段的文本字段没有打开,因为我将它作为第一响应者辞职..但是第一个字段的键盘没有辞职@
        【解决方案4】:

        为每个文本字段设置标签并签入

        -(BOOL)textFieldShouldReturn:(UITextField *)textField
        {
            if([textfield.tag == 1])
           {
               [textFieldFirst resignFirstResponder];
           }
           else
           {
             // your action sheet code here
           }
           return YES;
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-06-02
          • 1970-01-01
          • 2014-05-15
          • 1970-01-01
          • 2019-10-01
          • 2020-11-02
          • 1970-01-01
          • 2020-07-03
          相关资源
          最近更新 更多