Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode/iOS5: Show UIDatePicker when UITextField is pressed (+ hide default keyboard)

I'd like to call UIDatePicker only when UITextField is active. When the date is picked, it should be shown in the same UITextField.

I even don't know how to call the Picker.

Can anyone help me?

like image 225
filou Avatar asked Feb 07 '26 09:02

filou


1 Answers

there is a delegate method called

-(void)textFieldDidBeginEditing:(UITextField*)textField
{
[textField resignFirstResponder];
 in this you have to do this
pick = [[UIDatePicker alloc] init];
[pick setFrame:CGRectMake(0,200,320,120)];
[pick addTarget:self action:@selector(done) forControlEvents:UIControlEventValueChanged]
[self.view addSubview:pick];
}

in

-(void)done
{
[textfield setText:pick.date];
}

release the pick in dealloc

like image 51
Tendulkar Avatar answered Feb 09 '26 01:02

Tendulkar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!