I am trying to disable my post button if the user has not selected a picture to post, so far, I've only managed to disable it if the textfields have not been edited. I also have two buttons, button one: lost, button two: found. The user needs to tap one or the other as well. Is it possible to also disable the post button if neither of these two buttons have been tapped?
Here's my code so far!
func handleBlancInformation(){
address.addTarget(self, action: #selector(PostViewController.textFieldDidChange), for: UIControlEvents.editingChanged)
breed.addTarget(self, action: #selector(PostViewController.textFieldDidChange), for: UIControlEvents.editingChanged)
phone.addTarget(self, action: #selector(PostViewController.textFieldDidChange), for: UIControlEvents.editingChanged)
}
@objc func textFieldDidChange() {
guard let address = address.text, !address.isEmpty, let breed = breed.text, !breed.isEmpty, let phone = phone.text, !phone.isEmpty
else {
postButton.setTitleColor(UIColor.lightText, for: UIControlState.normal)
postButton.isEnabled = false
return
}
postButton.setTitleColor(UIColor.white, for: UIControlState.normal)
postButton.isEnabled = true
}