issue of hide uipickerview in iphone

Posted by M007 on Stack Overflow See other posts from Stack Overflow or by M007
Published on 2012-11-17T04:03:30Z Indexed on 2012/11/17 5:00 UTC
Read the original article Hit count: 157

enter image description here

I want to display UIPickerView with UIToolBar on the top of pickerView with done and cancel button.Attached is the screen shot for the same.I also have tab bar controller in bottom side of view and I want to display pickerView over bottom bar thats why I am using uipickerView inside of actionsheet.Now my issue is how to dismiss that pickerView on cancelButton click which is added in UIActionSheet?

Following is the function to display pickerView :

-(IBAction)setMile:(id)sender
   {
      menu = [[UIActionSheet alloc] initWithTitle:nil
                                                  delegate:self
                                         cancelButtonTitle:nil
                                    destructiveButtonTitle:nil
                                         otherButtonTitles:nil];
    // Add the picker
    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,55,0,0)];
    pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;    // note this is default to NO

UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];

NSMutableArray *barItems = [[NSMutableArray alloc] init];


UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(setMileCancel:)];
[barItems addObject:cancelBtn];
[cancelBtn release];
cancelBtn=nil;

UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
[flexSpace release];
flexSpace=nil;

UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(setMileDone:)];
[barItems addObject:doneBtn];
[doneBtn release];
doneBtn=nil;


[pickerToolbar setItems:barItems animated:YES];
[barItems release];
barItems=nil;

[menu addSubview:pickerToolbar];
[menu addSubview:pickerView];
[menu showInView:self.view];
//[menu showFromTabBar:[[self tabBarController] tabBar]];  this code is not working
[menu setBounds:CGRectMake(0,0,320, 545)];
[pickerView release];
[menu release];
pickerView=nil;
menu=nil;
}

I have following code on cancel button click

-(IBAction)setMileCancel:(id)sender
 {
   //[menu removeFromSuperview];
   [menu dismissWithClickedButtonIndex:0 animated:YES];
 }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uitabbarcontroller