I have a button in one class and textField in another. My goal is to achieve this: when textField is empty, the button is hidden, and then I add numbers to textField (it has 4 numbers), the button becomes visible.
I add target to my button:
let confirmButton: UIButton = {
let button = UIButton()
button.setTitle("Confirm", for: .normal)
button.layer.borderWidth = 1
button.layer.borderColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
button.translatesAutoresizingMaskIntoConstraints = false
button.addTarget(self, action: #selector(confirmation.textFieldDidEndEditing(_:)), for: .editingDidBegin)
return button
}()
And make this function in another class:
@objc func textFieldDidEndEditing(_ textField: UITextField) {
if textField.text != "" {
button.confirmButton.isHidden = false
} else {
button.confirmButton.isHidden = true
}
But nothing changed. Help me, please, that l have to do to achieve my goal?
Use textField's delegate method