DatePicker swift



  • When applied on any date, the data shall be transmitted on another screen. Everything works perfectly except today. She's chosen to be default and can't press today's number. How do I fix it?

    import UIKit
    

    protocol DatePickerViewControllerDelegate { func transferDate(_ date: String) ♪

    class DatePickerViewController: BackgroundVC {

    @IBOutlet weak var datePicker: UIDatePicker!
    var delegate: DatePickerViewControllerDelegate?
    

    override func viewDidLoad() {
    super.viewDidLoad()

    datePicker.maximumDate = NSDate() as Date
    datePicker.datePickerMode = .date
    datePicker.preferredDatePickerStyle = .inline
    
    let localeID = Locale.preferredLanguages.first
    datePicker.locale = Locale(identifier: localeID!)
    
    datePicker.addTarget(self, action: #selector(dateChanged), for: .valueChanged)
    

    }

    @objc func dateChanged(picker: UIDatePicker){

    let formatter = DateFormatter()
    formatter.dateFormat = "dd.MM.yyyy"
    let date = formatter.string(from: picker.date)
    delegate?.transferDate(date)
    dismiss(animated: true, completion: nil)
    

    }



  • Set the counter-resistant shut-down and send the date off. dateChangedAnd on the button, for example, in bar navigation, you now have a controller closing at any change in the date that might in itself be uncomfortable - and what if the user chooses a wrong date? Then to change it, you're gonna have to open up a controller with a poker again.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2