title: Button activated when date picker and text field are set in Swift
body: <p>I want to implement a function that activates the button when the text field and date picker are set.</p>
  <p>The value of the date picker goes to the label, and I checked the button by changing the label value.</p>
  <p>However, among other functions that I have implemented, if the navigation is popped using a singleton object and the value is saved when it comes back, if the button is checked with a label change, the button is not activated because it is duplicated with the singleton, or even if only the phone number is set. It happens that the button is activated.</p>
  <p>So, rather than changing the label, is there a way to catch it when the date picker itself changes the value?</p>
  <pre class="lang-swift prettyprint-override"><code>import UIKit
  
  class ThirdViewController: UIViewController {
      
      lazy var dateFormatter: DateFormatter = {
          let date = DateFormatter()
          date.dateStyle = .medium
          date.timeStyle = .none
          return date
      }()
      
      @IBOutlet weak var dateLabel: UILabel!
      @IBOutlet weak var numberTextField: UITextField!
      @IBOutlet weak var datePicker: UIDatePicker!
      @IBOutlet weak var signUpButton: UIButton!
      
      override func viewDidLoad() {
          super.viewDidLoad()
          numberTextField.addTarget(self, action: #selector(editingChanged(_:)), for: .editingChanged)
          numberTextField.text = UserInformation.userInformationSingleton.userNumber
          dateLabel.text = UserInformation.userInformationSingleton.dateLabel
      }
      
      @objc func editingChanged(_ textField: UITextField) {
          if textField.text?.count == 1 {
              if textField.text?.first == &quot; &quot; {
                  textField.text = &quot;&quot;
                  return
              }
          }
          toggleButton()
      }
      
      func toggleButton() {
          guard
              let textField = numberTextField.text, !textField.isEmpty,
              dateLabel.text != &quot;&quot;
              else {
                  signUpButton.isEnabled = false
                  return
          }
          signUpButton.isEnabled = true
      }
      
      @IBAction func datePickerValueChanged(_ sender: UIDatePicker) {
          dateLabel.text = dateFormatter.string(from: sender.date)
          toggleButton()
      }
      
      @IBAction func cancelButton(_ sender: UIButton) {
          self.dismiss(animated: true, completion: nil)
          UserInformation.userInformationSingleton.userID = nil
          UserInformation.userInformationSingleton.userNumber = nil
          UserInformation.userInformationSingleton.dateLabel = nil
      }
      
      @IBAction func tappedPreviousButton(_ sender: UIButton) {
          self.navigationController?.popViewController(animated: true)
      }
      
      @IBAction func tappedSignUpButton(_ sender: UIButton) {
          self.dismiss(animated: true, completion: nil)
      }
  }
  
  
  </code></pre>
  <p><a href="https://i.stack.imgur.com/a1GVc.png" rel="nofollow noreferrer">https://i.stack.imgur.com/a1GVc.png</a></p>
  <p>thanks for reading!!</p>