UIDatePicker: it is not possible to select default value
Asked Answered
R

3

6

I have created UIDatePicker and added target for event UIControlEventValueChanged. Default value of the date picker is set to the current date.

Date picker is shown when I click into text field. Then user can select date, click outside the view controller with the date picker, it disappears and text field is set to the selected date.

Problem is when the user wants to select current(default) date. It is necessary to change value from and back to the default value. It is because the date picker fires UIControlEventValueChanged event. I want also to let the user decide, if he wants to fill the date value (if he just clicks outside the view control with date picker).

How is it possible to let the user select the default value of the date picker without changing the value from and back to the default value?

Ran answered 16/9, 2011 at 10:35 Comment(0)
K
1

Is it acceptable for you to just set the date in the text field as soon as the text field is shown? That way the user doesn't need to do anything if the current date is what they want in the text field.

If the text field needs to start blank for some reason, then you could have the current date show in the text field as soon as the user first taps inside it (i.e. at the same time as you display the UIDatePicker).

If neither of these are acceptable, have you tried setting a target action for another control event, such as UIControlEventTouchDown / UIControlEventDragInside / UIControlEventEditingDidBegin?

Kentiga answered 16/9, 2011 at 10:45 Comment(1)
Your advice is good, but I have rather added button to confirm selected date and to hide popover controller with UIDatePickerRan
G
0

Add a private member called _isDateChanged, when UIControlEventValueChanged event action called, set it to YES. When the Popover will disappear, check if _isDateChanged is YES, if not, trigger a change action.

Gusman answered 26/4, 2013 at 2:32 Comment(0)
B
0

Simply take UIDatePicker view as global variable and assign datePicker.date (datePicker is global variable) wherever possible.

Bookerbookie answered 10/2, 2021 at 7:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.