Answer the question
In order to leave comments, you need to log in
How to track the state of a textField?
How to understand that the user has started typing text in a textField? By type willSet and didSet for a variable
Answer the question
In order to leave comments, you need to log in
UITextField inherits from UIControl, which means you can subscribe to its controlEvents. Example:
override func viewDidLoad() {
super.viewDidLoad()
textField.addTarget(self, action: #selector(editingBegan(_:)), for: .editingDidBegin)
textField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
textField.addTarget(self, action: #selector(editingEnded(_:)), for: .editingDidEnd)
}
@objc func editingBegan(_ textField: UITextField) {
//пользователь попал в поле, но еще ничего не ввел
}
@objc func editingChanged(_ textField: UITextField) {
//текст изменился
}
@objc func editingEnded(_ textField: UITextField) {
//ввод окончен, к примеру нажали "return" на клавиатуре
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question