Reputation: 58770
I'm trying to detect when the user change the input field.
I created this function
@objc func textFieldDidChange(_ textField: UITextField) {
let alert = UIAlertController(title: "Did you bring your towel?", message: "It's recommended you bring your towel before continuing.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
I added my Target like this
passWord.addTarget(self, action: #selector(textFieldDidChange(passWord:)), for: .editingChanged)
I kept getting this error
Use of unresolved identifier 'textFieldDidChange(passWord:)'
How do I prevent this error to happen ?
Upvotes: 0
Views: 214
Reputation: 53181
Your selector is wrong…
passWord.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .editingChanged)
See https://developer.apple.com/documentation/uikit/uicontrol/1618259-addtarget
Upvotes: 1