I\'d like to Display UIDatePicker only when user the UITextField is Clicked. When the date is picked, it should be shown in the same UITextField.I want to implement UIDatePicker
This will be simple, try this
When U click the textField, this method is called.
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
Then, we dont want to display the keyboard.
[textField resignFirstResponder];
Then, to display the datePicker
datePicker=[[UIDatePicker alloc]init];
[datePicker setFrame:CGRectMake()];
datePicker.datePickerMode=UIDatePickerModeDateAndTime;
datePicker.timeZone = [NSTimeZone localTimeZone];
[datePicker addTarget:self action:@selector(done) forControlEvents:UIControlEventValueChanged];
This will display the datePicker.
Then U want to display the selected value in textField
-(void)done
{
NSString *dateStri=[dateFormater stringFromDate:datePicker.date];
[timingTextField setText:[NSString stringWithFormat:@"%@",dateStri]];
}
Try this, and update me the result