Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, here is a <a href="http://screencast.com/t/NDViMjYxZGEt" rel="noreferrer">screencapture showing how this looks</a>.</p> <p>Implement UITextFieldDelegate and display a "popup" containing a UIPickerView.</p> <pre><code>- (void)textFieldDidEndEditing:(UITextField *)textField { UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 244, 320, 270)]; picker.delegate = self; picker.dataSource = self; [self.view addSubview:picker]; [picker release]; } </code></pre> <p>When the keyboard disappears, a picker view is then visible.</p> <p>If you want to take this a bit further, you can animate the UIPickerView "slide in" like the keyboard. </p> <pre><code>- (void)viewDidLoad { //picker exists in the view, but is outside visible range picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 480, 320, 270)]; picker.delegate = self; picker.dataSource = self; [self.view addSubview:picker]; [picker release]; } //animate the picker into view - (void)textFieldDidEndEditing:(UITextField *)textField { [UIView beginAnimations:@"picker" context:nil]; [UIView setAnimationDuration:0.5]; picker.transform = CGAffineTransformMakeTranslation(0,-236); [UIView commitAnimations]; } //animate the picker out of view - (void)textFieldDidBeginEditing:(UITextField *)textField { [UIView beginAnimations:@"picker" context:nil]; [UIView setAnimationDuration:0.5]; picker.transform = CGAffineTransformMakeTranslation(0,236); [UIView commitAnimations]; } //just hide the keyboard in this example - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return NO; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload