Powered By Blogger

Monday, June 11, 2012

How to put UIPickerView on UIActionSheet?

    Hello,
I'm going to explain you the combination of "UIPickerView" and "UIActionSheet".
Please check the below code. I hope you will definitely find it helpful.

UIActionSheet *actionSheet = [[[UIActionSheet alloc]initWithTitle:@"sasdasd" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil] autorelease];
    [actionSheet showInView:self.view];
    [actionSheet setBounds:CGRectMake(0, 0, 320, 470.0)];

    UIPickerView *pickerView = [[UIPickerView alloc]initWithFrame:CGRectMake(0.0, 44.0, 320.0, 250.0)];
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;
   
    UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    pickerToolbar.barStyle = UIBarStyleBlack;
    [pickerToolbar sizeToFit];
   
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
   
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [barItems addObject:flexSpace];
   
    UIBarButtonItem *btnBarCancel = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(btnBarCancelClicked:)];
    [barItems addObject:btnBarCancel];
   
    [pickerToolbar setItems:barItems animated:YES];
   
    [actionSheet addSubview:pickerToolbar];
    [actionSheet addSubview:pickerView];

    [flexSpace release];
    flexSpace = nil;
   
    [btnBarCancel release];
    btnBarCancel = nil;
   
    [barItems release];
    barItems = nil;

    [pickerToolbar release];
    pickerToolbar = nil;
   
    [pickerView release];
    pickerView = nil;

    [actionSheet release];

If any one has query then place you it over here.

Thanks and Regards,
Nilesh Prajapati
 

No comments:

Post a Comment