I'm guessing none of you have figured out how to do this yet?
Post
Replies
Boosts
Views
Activity
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!
March 28, 2021 - Still nothing!
It just doesn't work