- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
在 OTP 中,使用了四个文本字段。按下键盘后退按钮时将光标移动到上一个文本字段?
最佳答案
To detect the backspace event in a UITextField, first you need to set up a delegate for the UITextField and set it to self.
class ViewController: UIViewController,UITextFieldDelegate
self.textField.delegate = self
Then you use the delegate method below to detect if a backspace was pressed
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let char = string.cString(using: String.Encoding.utf8)
let isBackSpace: Int = Int(strcmp(char, "\u{8}"))
if isBackSpace == -8 {
print("Backspace was pressed")
}
return true
}
Basically this method detects which button you are pressing (or have just pressed). This input comes in as an NSString. We convert this NSString to a C char type and then compare it to the traditional backspace character (\u{8}). Then if this strcmp is equal to -8, we can detect it as a backspace.
选择 2
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if (string.characters.count ) == 0 {
//Delete any cases
if range.length > 1 {
//Delete whole word
}
else if range.length == 1 {
//Delete single letter
}
else if range.length == 0 {
//Tap delete key when textField empty
}
}
return true
}
关于ios - 想知道在文本字段编辑 ios 期间按下键盘后退按钮时的任何时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42642357/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!