繁体   English   中英

如何在Swift iOS中将光标从一个文本字段自动移动到另一个文本字段?

[英]How to move cursor from one text field to another automatically in swift ios?

    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
}

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

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

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.
    }

您也可以将返回键更改为next

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM