I have already researched this topic to death and found people posting the exact same question on a number of websites including right here in stackoverflow.
I have
add UITextField's delegate in .h file to call this function when touched. then use the text field's tag value to determine what you want to do when the field is selected.
-(BOOL) textFieldShouldBeginEditing:(UITextField *) textField
{
activeTextField = textField;
if (textField.tag == 1)
{
self.datePicker.datePickerMode = UIDatePickerModeDate;
self.isDatePicker = TRUE;
self.tempTextField = textField;
[self showPicker];
return NO;
}
else if (textField.tag == 2)
{
self.datePicker.datePickerMode = UIDatePickerModeTime;
self.isDatePicker = TRUE;
self.tempTextField = textField;
[self showPicker];
return NO;
}
else if (textField.tag == 3)
{
self.isDatePicker = FALSE;
self.tempTextField = textField;
[self showPicker];
return NO;
}
else
{
self.tempTextField = textField;
return YES;
}
}