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.
add inputview to textField.
picker = [[UIPickerView alloc]init];
[picker setDataSource:self];
[picker setDelegate:self];
[picker setShowsSelectionIndicator:YES];
MyTextField.inputView = picker;