Default date picker date no longer works with iOS 5 - iphone

I have a medical app that allows the user to calculate a patient's age based on date of birth entered with a date picker. For convenience, I set the default date for the date picker object in Interface Builder to 1/1/1950. However, I noticed that in iOS 5 the default date no longer sets when the date picker initially loads. The default date automatically becomes the upper date limit (if that parameter enabled in Interface Builder), or the current date if this upper limit is not enabled. The default date field in Interface Builder still has "1/1/1950" set. The same version of the app on an older device compiled with iOS 4 still works properly, with the date picker scrolling to 1/1/1950 on loading. I very much would appreciate any advice for fixing the problem. Thanks in advance.

In your ViewController's viewDidLoad, log the value of the picker. If it is not set correctly, then you can try setting the value programmatically in viewDidLoad.

Related

Time range on date picker for specific dates iPhone

I want to have a time range on a UIDatePicker, so I can display what times users can book a meeting. Say on May 25th, they can book between 12pm and 8 pm, if they scroll to May 26th they can book between 4pm and 8pm.
So I'm wondering how I can display this in a UIDatePicker? Users can't choose time outside of a preset I have for each day.
Any help is appreciated!
I found this one, hope this will help you out..
Can UIDatePicker's minimumDate and maximumDate include time?
Enjoy Coding :)
Sorry, but no. UIDatePicker can only set ranges for dates. If you want to restrict the range of the hours, you will have to subclass uidatepicker and create your own custom class.
Here's a link: UIDatePicker hours interval (NSCalendarUnit?)
Hope this helped!
I would suggest using UIPickerView to make your own date picker. Every time a date is selected, you can change what times are available inside pickerView:didSelectRow:inComponent:.
What I ended up doing was to add a target to the date picker, and check if the time of the date chosen matched the hours I preset and display an alert view if they didn't match.

Custom DatePicker with just two components

I want to to use custom datePicker in my project. In Mode date it shows Month,Day and Year, in my case I don't need Year, I just want to display Month and day.
The API does not provide a way to do this. If you want to be able to, please file a report requesting this ability, and it'll hopefully get included in a future release of iOS.
In the meantime, you can make a pretty convincing replica yourself using a UIPickerView.
Im sorry but following the reference of the PickerView
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDatePicker_Class/Reference/UIDatePicker.html#//apple_ref/doc/c_ref/UIDatePickerMode
It says that is not possible to do that, so your only option is to implemente yourself the delegate and the datasource, and create the pickerview with the data you need.

UIDatePicker Time gets reset on changing UIDatePicker's mode to UIDatePickerModeTime?

I am using UIDatePicker in my iPhone application.I have kept a button on clicking which the mode of datepicker switches between UIDatePickerModeTime and UIDatePickerModeDate.
When I change the date of datepicker when the mode is UIDatePickerModeDate,the changed date correctly appears when I switch the mode but if I change the time and switch the mode,on again switching the mode to UIDatePickerModeTime resets the time to 12:00 AM.I am not getting why this is happening and what to do for it.Please help.
I have a similar problem. The first time I change from UIDatePickerModeDate to UIDatePickerModeTime, the time was OK. However, when I change back to the ..Date mode and then to the ..Time mode again, the time read 00:00. Thereafter, regardless of the number of mode changes, the time always remained at 00:00. I modeled my UIDatePicker programmatically the same as the UIDatePicker in Apple's UICatalog app. This behavior does not exist in their app.
Taking your lead, I saved the NSDate value from the picker in a retained #property with the intentions of retrieving and resetting the picker upon a UIControl Notification. However, I could not find an event that fired when the picker was changed from Date mode to Time mode. I even tried something like:
[myDatePicker addTarget:self action:#selector(getDateTime:) forControlEvents:UIControlEventAllEvents];
Of course the event fired if I changed the picker's date (or time) but as I mentioned, not when I changed the mode.
I eventually ended up using a UISegmentedControl (same as in the UICatalog app) that targeted the same event method above where I toggled the mode. However, when I reset the picker to the saved NSDate value, the Time remained at 00:00. I then used NSLog to verify that the saved value was OK and discovered that its Time value portion had also changed to 00:00! This was indeed strange since I had not saved a new NSDate value. The original saved value simply changed on it's own!
I'm still investigating the problem and am very close to calling it a bug, especially when a UIDatePicker is added programmatically without a supporting NIB.
Update:
My final solution was almost identical to yours. For some reason, the error continued when the saved date was stored as an NSDate value. Storing it as an NSString and typecasting both ways did the trick:
self.saveDate = (NSString*)self.myDatePicker.date;
...
[self.myDatePicker setDate:(NSDate*)self.saveDate animated:NO];
Also, since I'm retrieving and saving the date to an external device via a GCD dispatch_async block, the property, self. notation was also needed (even on the main_que).
Final conclusion:
I'm now convinced that setting the UIDatePicker date each and every time the picker is accessed is a necessary requirement rather than a bug. Using Apple's UICatalog app, when you set the date to today just once and then switch between Date and Time mode, their app exhibits exactly the same behavior. The date is retained but the time resets to 00:00. if you switch to a mode other than date or time and switch back, all modes will be reset to their floor values.
I used a Date object which I declared as a property in which I stored the date from the date picker when I present the date picker.
I updated the stored date when I changes the date in date picker(Using UIControl Notification)
On changing the mode of the date picker I assigned the same date to the date picker.
I understand this was fairly simple but formerly I was trying the same thing by taking a simple Date object which didn't work.Making it a property did the job for me

Remove the "Today" entry from UIDatePicker

When using a UIDatePicker in iOS SDK, there is always an entry "Today" at the current date.
That's useful in most cases, but where I need it, it's rather confusing.
Is there a way to:
a) disable the "today"-entry (use regular date instead), and have all entries look the same
or even better
b) disable the "today"-entry (use regular date instead), and color the next day in blue
Further more, the application is for private use only, it's not going to get distributed on the AppStore, which means I could use private APIs (I still would rather avoid them) and I don't need it to be backwards compatible. iOS 4 is fine.
I had a similar problem with the UIDatePicker not matching my requirements exactly (in my case I needed a datepicker without a year wheel). Having a look at the UIDatePicker reference, it doesn't look like you can disable the today entry, so you might be forced to do what I did.
I used a UIPickerView and re-implemented the date selection functionality I needed with that. There are a few things you will need to do to implement your custom date picker:
Implement a UIPickerViewDataSource to set up row titles, dimensions and row counts.
Implement a UIPickerViewDelegate to handle events from your custom picker.
Make sure you update your day wheel when the month wheel changes so you get appropriate days for each month. UIDatePicker does this pretty seamlessly. With limited time, I just reload the picker when the month changes so the day counts match up.

UIDatePicker hours interval (NSCalendarUnit?)

I'm trying to make a UIDatePicker which allows the selection of hours only between 6.00 and 17.00. The other hours shall be inactive but still visible.
I think it can be done with setting up the picker calendar and then use this:
- (NSRange)maximumRangeOfUnit:(NSCalendarUnit)unit
but I'm not sure how.
Maybe someone can help me.
Thank you!
Sorry, but UIDatePicker doesn't support setting valid time ranges like you describe. The only options are minimum and maximum dates.
You'll either need to build a custom control from scratch or try to subclass UIDatePicker, but that's not a path I'd recommend.