Search code examples
iphoneuitabbarcontrolleruipickerviewuiactionsheet

issue of hide uipickerview in iphone


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];
 }

Solution

  •  //   menu=nil;
     Please comment this line, then it will work