Post

Replies

Boosts

Views

Activity

Reply to UIDatePicker as countdown not triggering Value Changed event
I have found the same issue while trying to create a UIViewRepresentable for a UIDatePicker while working with a countdown timer. The workaround found by @brianfrombrighton did not work for me. What did work was setting the minuteInterval. This is my UIViewRepresentable struct PickerView: UIViewRepresentable {     @Binding var selection: Double         func makeUIView(context: Context) - UIDatePicker  {         let picker = UIDatePicker()         picker.datePickerMode = .countDownTimer         picker.preferredDatePickerStyle = .automatic         picker.minuteInterval = 5         picker.countDownDuration = selection         picker.addTarget(context.coordinator, action: #selector(PickerView.Coordinator.didSelectTime), for: .allEvents)         return picker     }     func updateUIView(_ uiView: UIDatePicker, context: Context) {     }     func makeCoordinator() - PickerView.Coordinator {         Coordinator(self)     }     class Coordinator: NSObject, UIPickerViewDelegate {         var parent: PickerView         init(_ pickerView: PickerView) {             self.parent = pickerView         }         @IBAction func didSelectTime(sender: UIDatePicker, forEvent event: UIEvent) {             parent.selection = sender.countDownDuration         }     } } Hope it helps anyone in the future!
Apr ’21