用户在 UITextField 中输入文本后,控件应自动切换

发布于 2024-10-27 01:58:10 字数 98 浏览 0 评论 0原文

在我的应用程序中,我有两个文本字段,我希望用户在第一个文本字段中自动输入值后,将一个文本字段中的控件切换到第二个控件。

有人对此有任何想法吗?

谢谢,

In my app i have two textfields and i want the control from one text field to switch to second control as soon as the user is done entering the values in the first textfield automatically.

Does anybody has any idea on this?

Thanks,

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

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

发布评论

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

评论(1

流绪微梦 2024-11-03 01:58:10

我假设“完成输入”意味着用户点击键盘上的 return, ... 按钮。

UITextField 有 UITextFieldDelegate 协议的委托。这里的方法......

- (BOOL)textFieldShouldReturn:(UITextField *)textField

你可以用这种方式实现它......

...
self.myFirstTextField.delegate = self;
self.mySecondTextField.delegate = self;
...

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  if ( textField == self.myFirstTextField ) {
    // User hits return key on keyboard when editing first textfield
    [mySecondTextField becomeFirstResponder];
  } else if ( textField == self.mySecondTextField ) {
    // User hits return key on keyboard when editing second textfield
    // This simply removes focus from the second textfield and hides keyboard
    [mySecondTextField resignFirstResponder];
  }
  return YES;
}

如果“完成输入”没有返回,......键盘上的按钮,你可以实现这个委托的方法......

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

检查UITextField的用户键入时的文本。

I assume "done entering" means the user hits return, ... button on keyboard.

UITextField has delegate with UITextFieldDelegate protocol. And here's method ...

- (BOOL)textFieldShouldReturn:(UITextField *)textField

... you can implement it in this way ...

...
self.myFirstTextField.delegate = self;
self.mySecondTextField.delegate = self;
...

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
  if ( textField == self.myFirstTextField ) {
    // User hits return key on keyboard when editing first textfield
    [mySecondTextField becomeFirstResponder];
  } else if ( textField == self.mySecondTextField ) {
    // User hits return key on keyboard when editing second textfield
    // This simply removes focus from the second textfield and hides keyboard
    [mySecondTextField resignFirstResponder];
  }
  return YES;
}

If "done entering" is not return, ... button on keyboard, you can implement this delegate's method ...

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string

... to check UITextField's text when user did type.

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