【问题标题】:How to move cursor from one text field to another automatically in swift ios?如何在swift ios中自动将光标从一个文本字段移动到另一个文本字段?
【发布时间】:2016-02-10 13:45:05
【问题描述】:
    func textFieldDidBeginEditing(textField: UITextField) {
    scrlView.setContentOffset(CGPointMake(0, textField.frame.origin.y-70), animated: true)
}

func textFieldShouldReturn(textField: UITextField) -> Bool {


    textField.resignFirstResponder()

    scrlView .setContentOffset(CGPointMake(0, 0), animated: true)

    return true
}

在第一个文本字段中输入值后,如何将光标从一个文本字段自动移动到另一个文本字段?

【问题讨论】:

  • 如何知道用户是否完成了在字段中输入值?
  • 是的。我也有同样的问题。。

标签: ios swift uitextfielddelegate


【解决方案1】:

首先,您需要在文本字段中按顺序添加标签

func textFieldShouldReturn(textField: UITextField) -> Bool {

        let nextTag = textField.tag + 1;
        // Try to find next responder
        var nextResponderTxt: UITextField!
        nextResponderTxt = textField.superview?.viewWithTag(nextTag) as? UITextField
        if ((nextResponderTxt) != nil) {
            // Found next responder, so set it.
            nextResponderTxt.becomeFirstResponder()
        } else {
            // Not found, so remove keyboard.
            textField.resignFirstResponder()
        }
        return false; // We do not want UITextField to insert line-breaks.
    }

您也可以将返回键更改为下一个

【讨论】:

  • 如何知道用户是否完成了在字段中输入值?
  • @RakeshMohan 当我完成击键时,可以通过委托的方式检测到按下键时。 textFieldDidBeginEditingtextFieldDidEndEditingValue Changed 事件
  • 你能用代码解释一下吗?由于我是 ios 新手,我在理解代码方面遇到了困难..
  • 让长度 = textField.text!.utf16.count + string.utf16.count - range.length 返回长度
  • 我在委托方法中的 should character change 中添加了上述代码,以将字符限制为 1
猜你喜欢
  • 1970-01-01
  • 2016-05-21
  • 1970-01-01
  • 1970-01-01
  • 2017-08-07
  • 1970-01-01
  • 1970-01-01
  • 2014-05-16
  • 1970-01-01
相关资源
最近更新 更多