【问题标题】:How to move one text field to another using keyboard return key in swift3 ios如何在swift3 ios中使用键盘返回键将一个文本字段移动到另一个文本字段
【发布时间】:2017-10-13 16:56:49
【问题描述】:

通过这个带有 done btn 的 img 移动到下一个文本字段 (https://i.stack.imgur.com/cDHlh.jpg)

【问题讨论】:

  • 欢迎来到 Stack Overflow。请花几分钟查看tour 并阅读help center 页面,尤其是How to Ask,然后回来edit 您的问题。谢谢。
  • 作为初学者,请尽可能多地解释您的问题。对于您的问题 uitextfield 有一个方法 'becomeFirstResponder' 所以按钮操作你必须把 [yourTextField becomeFirstResponder]

标签: ios swift3


【解决方案1】:

我怀疑你是否可以使用“完成”按钮来做到这一点,但你可以通过

使用返回键来实现
  1. 让你的班级成为 UITextField 代表

    class VC: UIVIewController, UITextFieldDelegate
    
  2. 在您的 ViewDidLoad 方法中执行此操作 -

    textField1.becomeFirstResponder()
    

这样当用户进入此屏幕时,第一个文本字段将直接变为活动状态(不是正确的词,而是使用该词,因为没有更好的选择)

  1. 当你需要它在他按下返回时移动到下一个文本字段时,

    func textFieldShouldReturn(textField: UITextField) -> Bool {
        textField1.resignFirstResponder()
        if (textField == textField1){
            textField2.becomeFirstResponder()
        }
        else if (textField == textField2){
            textField3.becomeFirstResponder()
        }
        return true
    }
    

您也可以在上述委托方法中使用 switch case。正如问题中的评论所述,请务必浏览链接并了解如何正确提问,并提供尽可能多的细节。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-07
    • 2016-01-20
    • 1970-01-01
    相关资源
    最近更新 更多