Fix custom format bug in datePickerValueChagned method.
Closed this issue · 0 comments
datePickerValueChanged bug:
//Doesn't check for self.dataFormat
//NOW:
-
(void)datePickerValueChanged:(id)sender{
UIDatePicker datePicker = (UIDatePicker)sender;NSDate *selectedDate = datePicker.date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[
dateFormatter setDateFormat:@"MM/dd/YY"];[_textField setText:[dateFormatter stringFromDate:selectedDate]];
[self validate];
}
WITH FIXED BUG:
-
(void)datePickerValueChanged:(id)sender{
UIDatePicker datePicker = (UIDatePicker)sender;NSDate *selectedDate = datePicker.date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
if (self.dateFormat) {
[dateFormatter setDateFormat:self.dateFormat];
} else {
[dateFormatter setDateFormat:@"MM/dd/YY"];
}[_textField setText:[dateFormatter stringFromDate:selectedDate]];
[self validate];
}