【问题标题】:Dismissing the keyboard with a uibutton when there are multiple text fields? [duplicate]当有多个文本字段时,用 uibutton 关闭键盘? [复制]
【发布时间】:2014-07-15 12:20:21
【问题描述】:

我知道在触摸按钮时,我可以通过实现以下操作将单个文本字段分配给第一响应者:

- (IBAction)signMeUpButton:(id)sender {


     [self.textfield resignFirstResponder];
}

但是,就我而言,我有多个文本字段,我想一次输入一个,这可能不是最好的/最现代的方式。

我查看了网站上的多个问题,例如这个:

iOS SDK: Dismiss keyboard when a button gets clicked?

但他们都没有提到,有多个文本字段并用IBAction 将它们解雇......在这种情况下我该怎么办?

【问题讨论】:

标签: ios objective-c uitextfield


【解决方案1】:

你可以试试这个:

- (IBAction)signMeUpButton:(id)sender
{
     [self.view endEditing:YES];
}

【讨论】:

    【解决方案2】:

    如果你有多个文本字段,最好实现以下

    [self.view endEditing:YES];
    

    所以,在你的情况下是:

        - (IBAction) signMeUpButton:(id)sender {
          [self.view endEditing:YES];
          }
    

    这将完全符合您的要求!

    【讨论】:

      【解决方案3】:

      试试这个

      UITextField *currentTextField;
      
      
      - (void)textFieldDidBeginEditing:(UITextField *)textField
      {
            currentTextField = textField;
      }
      
      -(IBAction)click:(id)sender
      {
            [currentTextField resignFirstResponder];
      }
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-24
      • 1970-01-01
      • 2012-02-24
      • 2015-08-18
      • 1970-01-01
      • 2013-06-27
      相关资源
      最近更新 更多