Working with UIDatePickers for the first time. To start, I'm just trying to update a text field with whatever value is selected from the datePicker (set in count down mode).
It works, but only the second time that a user selects a time. My action, durationSelected() is only called the second time, so there are no problems updating the textField.
Here's how I configured the date picker in my storyboard:
Here's the action triggered on Value Changed:
from DetailViewController.m
- (IBAction)durationSelected:(UIDatePicker *)sender
{
self.durationTextField.text = [NSString stringWithFormat:@"%f seconds", sender.countDownDuration];
}
I've tried setting a default value, which had no effect.
What's going on?
This seems to be a bug in the iOS 7 implementation of UIDatePicker. I'd suggest filing a radar on it.
Building on the iOS 6 SDK and running on an iOS 6 device will work, while running on an iOS 7 device will not.
You can fix it by adding this line of code to your - (void)viewDidLoad
method
[self.datePicker setDate:[NSDate date] animated:YES];