Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to use <code>UIPopOverController</code>.</p> <p>First, create a UIPickerViewController for <strong>iPhone</strong>. You need it for the nib, which will be pushed into the popOver. Initialize the picker in <code>ViewWithPicker</code></p> <p>.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class ViewWithPickerController; @protocol PopoverPickerDelegate @required - (void) viewWithPickerController:(ViewWithPickerController*) viewWithPickerController didSelectValue:(NSString*) value; @end @interface ViewWithPickerController : UIViewController &lt;UIPickerViewDelegate, UIPickerViewDataSource&gt; { IBOutlet UIPickerView *pickerView; id&lt;PopoverPickerDelegate&gt; delegate; NSMutableArray *array; } @property(nonatomic, retain) IBOutlet UIPickerView *pickerView; @property(nonatomic, assign) id&lt;PopoverPickerDelegate&gt; delegate; @end </code></pre> <p>.m, after you initialized the <code>array</code> in <code>viewDidLoad</code>, picker methods:</p> <pre><code>// returns the number of 'columns' to display. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)picker { return 1; } // returns the number of rows in each component. - (NSInteger)pickerView:(UIPickerView *)picker numberOfRowsInComponent:(NSInteger)component { return [array count]; } //returns the string value for the current row - (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent:(NSInteger)component { return [array objectAtIndex:row]; } //handle selection of a row - (void)pickerView:(UIPickerView *)picker didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSString *value = [pickerView.delegate pickerView:picker titleForRow:row forComponent:component]; //notify the delegate about selecting a value if(delegate != nil) [delegate viewWithPickerController:self didSelectValue:value]; } </code></pre> <p>Then, import the viewWithPicker into your main class, create a button and give it this action:</p> <pre><code>- (IBAction) showPickerPopupAction:(id) sender { self.viewWithPickerController = [[[ViewWithPickerController alloc] initWithNibName:@"ViewWithPicker" bundle:[NSBundle mainBundle]] autorelease]; viewWithPickerController.contentSizeForViewInPopover = CGSizeMake(viewWithPickerController.view.frame.size.width, viewWithPickerController.view.frame.size.height); viewWithPickerController.delegate = self; self.popoverController = [[[UIPopoverController alloc] initWithContentViewController:viewWithPickerController] autorelease]; [self.popoverController presentPopoverFromRect:popoverButtonForPicker.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; popoverController.delegate = self; } </code></pre> <p>And to select a specific value</p> <pre><code>- (void) viewWithPickerController:(ViewWithPickerController*) viewWithPickerController didSelectValue:(NSString*) value { yourLabel.text = [NSString stringWithFormat:@"%@ ",value]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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