filou
filou

Reputation: 1619

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?

Upvotes: 3

Views: 9201

Answers (2)

jbat100
jbat100

Reputation: 16827

To add to Hitman's answer, I think you should implement the

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

instead and return NO. Then show the date picker and fill the UITextField text according to the picker selection.

Upvotes: 1

Tendulkar
Tendulkar

Reputation: 5540

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

Upvotes: 4

Related Questions