Move cursor backward on deleting form one textfield to another in swift
I have used these code for moving the cursor from one to another UITextField ie
tField1 -> tField2 -> tField3 -> tField4
But I want to move reverse on delete textField
tField4(deleted)-> tField3(move cursor without clear text)
tField3(deletd)-> tField2(move cursor without clear text)
and so on... When I use becomeFirstResponder() it clear text
override func viewDidLoad() {
super.viewDidLoad()
tField1.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
tField2.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
tField3.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
tField4.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tField1.becomeFirstResponder()
}
@objc func textFieldDidChange(textField: UITextField) {
let text = textField.text
if text?.utf16.count == 1{
switch textField{
case tField1:
tField2.becomeFirstResponder()
case tField2:
tField3.becomeFirstResponder()
case tField3:
tField4.becomeFirstResponder()
case tField4:
tField1.becomeFirstResponder()
default: break
}
}
}
链接地址: http://www.djcxy.com/p/73510.html
上一篇: 我如何制作Karma的汽车