如果用户尚未选择要发布的图片,我试图禁用发布按钮,到目前为止,只有在未编辑文本字段的情况下,我才设法禁用它。我也有两个按钮,按钮一:丢失,按钮二:找到。用户也需要点击一个或另一个。如果没有同时点击两个按钮,是否也可以禁用发布按钮?
到目前为止,这是我的代码!
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
}
答案 0 :(得分:0)
func handleBlancInformation(){
address.addTarget(self, action: #selector(PostViewController.textFieldDidChange), for: .valueChanged)
breed.addTarget(self, action: #selector(PostViewController.textFieldDidChange), for: .valueChanged)
phone.addTarget(self, action: #selector(PostViewController.textFieldDidChange), for: .valueChanged)
}
尝试此代码,我已更改addTarget事件,因此它将起作用:)