How do you do a popup UIPickerView ?
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?
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?
Ok, so I created my own class called UIPopupPickerView
.h
.m
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.
.h
Code:
@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;
@end.m
Code:
#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;
}
@endThe 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.

