iPhone datepicker instead of keyboard?

xpepermint picture xpepermint · Jan 24, 2011 · Viewed 21.8k times · Source

How would you do that?

I have a form with a UITextField. When I click in it I would like to display a UIDatePicker instead of the default Keyboard that pops-up by default? Note that there are also other elements on my form.

Answer

Johan Kool picture Johan Kool · Apr 8, 2011

I think this is a more official way to do this:

UIDatePicker *datePicker = [[[UIDatePicker alloc] init] autorelease];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
datePicker.tag = indexPath.row;
textField.inputView = datePicker;