我试图使用实现了其委托功能的UITextField
处理用户输入。
这是一个变量,我将其从情节提要拖动到我的viewController
class DailPadViewController: UIViewController, UITextFieldDelegate{
@IBOutlet weak var numberTextField: UITextField!
这是我在viewDidload()中调用的代表
override func viewDidLoad() {
super.viewDidLoad()
PermissionAppUser.AskAudioPermission()
numberTextField.isUserInteractionEnabled = false
numberTextField.delegate = self
customizeBtnStyle()
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(deletedAll))
delete.addGestureRecognizer(longPress)
}
我实现了这个委托,但从未调用...
func textFieldDidBeginEditing(_ textField: UITextField) {
print("Text begin editing")
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let currentText = textField.text ?? ""
guard let stringRange = Range(range, in: currentText) else { return false }
let updatedText = currentText.replacingCharacters(in: stringRange, with: string)
return updatedText.count <= 9
}
编辑:添加功能viewDidload
答案 0 :(得分:0)
如果您不想显示键盘,请使用此代码
numberTextField.inputView = UIView()