【问题标题】:Shift focus to next field when Enter is pressed按下 Enter 时将焦点转移到下一个字段
【发布时间】:2014-05-30 07:56:09
【问题描述】:

我在将焦点转移到 Ipad 中的下一个文本字段时遇到问题。

场景:

[TEXTFIELD1] [TEXTFIELD2]

当在 TEXTFIELD1 上按下回车键时,将焦点转移到 TEXTFIELD2。

我已经搜索了解决方法并尝试了它们,但没有任何效果。

请帮帮我。

【问题讨论】:

标签: jquery jquery-mobile focus mobile-safari


【解决方案1】:

最简单的方法是设置文本字段的标签属性

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

   UITextField *nextField = (UITextField*)[self.view viewWithTag:textField.tag + 1];
   // if a textfield with this tag exist make it first responder
   if(nextField)
   {
     [nextField becomeFirstResponder];
   }
   else
   {
     // hide keyboard
     [self.view endEditing:YES];
   } 

    return YES;
}

【讨论】:

    【解决方案2】:

    您应该为您的文本字段创建 2 个 IBOutlets,并为它们设置委托。

    你必须在委托中实现这个方法:

    - (void)textFieldShouldReturn:(UITextField *)textField {
        if (textField == self.textField1) {
            [self.textField2 becomeFirstResponder];
        }
        return YES;
    }
    

    现在,当用户在 textField1 中按下 return 时,textField2 将成为焦点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      • 2023-03-27
      • 2017-05-08
      • 2012-05-11
      • 1970-01-01
      • 2014-05-16
      • 1970-01-01
      相关资源
      最近更新 更多