1

When an UITextField is firstResponder, I would like to bring to front an UIDatePicker (bottom part of the screen) without the "going down keyboard" (no call to UITextField resignFirstResponder).

The aim is to process like UIKeyboard of UITextField which pop-up on nearly everything when it becomeFirstResponder. modalViewController seems to be fullscreen only.


- showDatePicker:(id)sender {
    if([taskName isFirstResponder]) [taskName resignFirstResponder];
    [self.view.window addSubview: self.pickerView];

    // size up the picker view and compute the start/end frame origin
    (...)
    [UIView commitAnimations];

}

This example is an animation of keyboard going down, and DatePicker going up, behind and not in front.

Do you know a solution ? A piece of code would be welcome. Thanks in advance.

2 Answers 2

8

This is simply done by setting the input view of the text field to the Picker View. Then, on Editing did begin tell the picker view to becomeFirst responder. Like this

textField.inputView = pickerView

then using an IBAction called when the Editing Did Begin

-(IBAction) setPickerViewAsFirstResponder:(id)sender
{
    [pickerView becomeFirstResponder];
}

This works perfectly. You'll need to implement code to actually set what the picker view is currently showing to be a string in the text field still.

0
2

This definitely can be done... simply implement the method below after setting UIViewController <UITextFieldDelegate> in your .h

Long story short, this overrides the keyboard loading before text editing begins.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    // Make a new view, or do what you want here
    UIDatePicker *pv = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,245,0,0)];
    [self.view addSubview:pv];
    return NO;  
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.