I have a UIDate Picker embedded in a static TableViewCell and at the moment I disabled most of the code except the code responsible for the date picker.
I\'m using t
I don't know if I got your problem, but Date picker works using the target-action pattern and it triggers this mechanism when you change a value.
So if the problem is the very first value shown, you should initialize your variable taking it as the "default" value.
Actually, all you need is to not set datePicker.countDownDuration
in viewDidLoad
but add it to viewDidAppear
, or later.
Similar problem as above, I used
DispatchQueue.main.asyncAfter(deadline: .now()) {
self.datePicker.countDownDuration = 60
}
to put it on the next runloop. Seems a viable workaround.
Time ago I found another problem that somehow resembles this one. It was about presenting a view controller from within the tableView:didSelectRowAtIndexPath:
and the problem was that it was taking lots of time for the new controller to actually show up. One of the workarounds turned out to be using dispatch_async
on the main queue. The same worked for me in this case.
In my viewDidLoad
, I asynchronously dispatched the picker setup code on the main queue and, in my case, it started to respond to the valueChanged
event even on the first pick:
DispatchQueue.main.async {
self.pickerView.datePickerMode = .countDownTimer
self.pickerView.minuteInterval = 5
self.pickerView.countDownDuration = 15
}
I think you should try implement this delegate instead
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
It seems to be something to do with the animated parameter. You just need this line:
datePicker.setDate(date, animated: true)