【问题标题】:Keyboard is going out while moving one text field to another text field将一个文本字段移动到另一个文本字段时键盘熄灭
【发布时间】:2018-01-17 13:13:10
【问题描述】:

我有两个文本字段,分别是 emailTextField 和 passwordTextField。

我编写了以下文本字段委托方法,用于将一个文本字段移动到另一个文本字段:

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

    if (textField == emailTextField) {

        [textField resignFirstResponder];
        [passwordTextField becomeFirstResponder];
    } else if (textField == passwordTextField) {

        [textField resignFirstResponder];

    }

    return YES;
}

当我在输入电子邮件后单击下一步按钮时,它将转到密码文本字段,但在几分之一秒内,键盘将消失。

解决办法是什么?代码有错误吗?

【问题讨论】:

  • 你在textFieldDidBeginEditing方法中写了什么吗?
  • 没有。我没有在 textFieldDidBeginEditing 中写任何东西。
  • 您可以在这种情况下使用 iqKeyboard 管理器。 github.com/hackiftekhar/IQKeyboardManager

标签: ios objective-c uitextfield resignfirstresponder


【解决方案1】:

试试这个

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

   if (textField == emailTextField) { 

      [passwordTextField becomeFirstResponder];

  } else if (textField == passwordTextField) {

       [textField resignFirstResponder];

  }

  return YES;
}

【讨论】:

  • 在进入 passwordTextField 后键盘仍在运行。它移动到 passwordTextField 但在几秒钟内键盘将消失。
  • 看看有没有目标textFieldShouldReturn to password textfeild in project
  • 在项目中,任何你写[passwordTextField resignFirstResponder];[self.view endEditing:YES]的地方??
  • 我使用 urlTextField 像 [self.urlTextfield becomeFirstResponder];它在同一个视图控制器中
  • 一次应该成为FirstResponder
猜你喜欢
  • 2017-08-07
  • 1970-01-01
  • 2021-03-18
  • 1970-01-01
  • 2012-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多