Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show pickerview in uitextfield not the keyboard?

I want to show a UIPickerView on becoming FirstResponder of a UITextfield not the keyboard and fill the value in text field form the picker view.

any one knows this?

like image 866
Rahul Vyas Avatar asked May 25 '09 09:05

Rahul Vyas


2 Answers

Use [textfield setInputView:pickerView];

Replacing the System Input Views
inputView
inputAccessoryView

like image 107
mafonya Avatar answered Oct 21 '22 20:10

mafonya


Edit: this answer was correct at the time of writing. Apple has since introduced inputView. Mafonya answer is what you should be doing nowadays.

It is possible to prevent the keyboard from popping up. Set your class to be the delegate of the UITextField: textField.delegate = self and add: <UITextFieldDelegate> after your interface declaration (before the {) in the header file.

Now implement textFieldShouldBeginEditing::

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    // Show UIPickerView

    return NO;
}

If you want to be able to hide your pickerView this method won't work. What you could do then is create subclass of UITextField and override the *trackingWithTouch:event: selectors and do your magic in those. You probably still need to return NO from textFieldShouldBeginEditting: to prevent the keyboard from showing.

like image 28
klaaspieter Avatar answered Oct 21 '22 20:10

klaaspieter