How do you do a popup UIPickerView ?

Posts: 38
Joined: 2008.09
Post: #1
Recently I have seem some apps when the user is presented with a several choices, the user clicks a button, the UIPickerView pops up (like an UIActionSheet), the user makes a selection and then clicks a done button which is part of the sheet that pops up.

Is this a custom control? I havent seen anything like this is the books that I am reading. Is there open source code for something like this?
Quote this message in a reply
Posts: 38
Joined: 2008.09
Post: #2
Ok, so I created my own class called UIPopupPickerView
@interface UIPopupPickerView : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource> {
    IBOutlet UIToolbar *toolbar;
    IBOutlet UIBarButtonItem *barDone;
    IBOutlet UIPickerView *picker;
    NSArray *list;
@property (nonatomic, retain) UIToolbar *toolbar;
@property (nonatomic, retain) UIBarButtonItem *barDone;
@property (nonatomic, retain) UIPickerView *picker;
@property (nonatomic, retain) NSArray *list;

- (IBAction)doDoneButton:(id)sender;

#import "UIPopupPickerView.h"

@implementation UIPopupPickerView
@synthesize toolbar, barDone, list, picker;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    return self;
- (void)viewDidLoad {
    [super viewDidLoad];
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
- (void)dealloc {
    [picker release];
    [list release];
    [barDone release];
    [toolbar release];
    [super dealloc];

- (IBAction)doDoneButton:(id)sender
    [self.navigationController dismissModalViewControllerAnimated:YES];
#pragma mark -
#pragma mark UIPickerView DataSource methods
- (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{ return 1; }

- (NSInteger)pickerView: (UIPickerView *)pView numberOfRowsInComponent: (NSInteger) component
{ return [list count]; }

#pragma mark UIPickerView Delegate methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    NSString * title =  [list objectAtIndex:row];
    return title;

The idea is to display the view on top of the current view, but do not cover the whole view. So in the XIB I made the height of the view about 300px, but the problem is that it still takes up the whole area.

How do I stop the view from covering the whole area?

I would attach the xib file but I cant add attachments.
Quote this message in a reply
Post Reply