2

I have a UIDatePicker set for UIDatePickerModeTime. I am using the following code to set the time in my datePicker:

[self.oTimePicker setDate:dateFromString(self.oStartTime.text, @"HH:mm")];
[self.oTimePicker reloadInputViews];

which works but then the datePicker appears gray in color (see image below; it appears the datePicker is disabled), and sets the time to 06:00, no matter what is selected. Here is an image of the results; notice that I have picked 1:30 PM, but the text box shows 06:00; in addition, no matter what I select, nothing changes (the time displays what I pick (here 1:30 PM), but the value in the datePicker remains at 14:00 (but doesn't show 14:00 verified with NSLog), no matter what I select. Any ideas of what could be causing this?

enter image description here

SpokaneDude
  • 4,856
  • 13
  • 64
  • 120
  • Probably very obvious but have you got user interaction enabled on the date picker? - Just tested not going to be this. – Woodstock Aug 04 '13 at 21:38
  • I think maybe the time you are setting from the string is causing issues with the UIDatePicker - check this by setting the date correctly using this: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy'-'MM'-'dd"];; NSDate *anyDate = [dateFormat dateFromString:@"2019-09-11"]; [datePicker setDate:anyDate]; [dateFormat release]; – Woodstock Aug 04 '13 at 21:45
  • John... it's not the "date"... it's the "time"... and my code is above. SD – SpokaneDude Aug 04 '13 at 23:00

1 Answers1

3

It looks like you are having a time-zone issue with UIDatePicker. That is why it is showing one time in a UIDatePicker and another in your label (Washington has -7 time difference). There are lot of questions and answers about this topic (one example: iphone UIDatePicker showing wrong date in Central Timezone).

Another problem you are having is that UIDatePicker becomes disabled. This issue can be caused if you are setting datePicker.minimumDate to current date and using UIDatePickerModeTime.

Community
  • 1
  • 1
JPetric
  • 3,838
  • 28
  • 26
  • Got it! I had both the minimum and maximum dates checked in IB... removed that and it works like a champ! Thank you so much for your help... I truly appreciate it! – SpokaneDude Aug 10 '13 at 18:34