Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to dismiss action sheet

i used this code to show uipicker in uiactionsheet but when i click close button i want to remove action sheet from view. so what should be the code for removing actionSheet form view.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 40, 0, 0);

pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;

[actionSheet addSubview:pickerView];
[pickerView release];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]];
closeButton.momentary = YES; 
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[closeButton release];

[actionSheet showInView:self.view];//[UIApplication mainWindow]];

[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
 return false;
}
like image 376
Iqbal Khan Avatar asked Apr 20 '11 06:04

Iqbal Khan


3 Answers

All you need to do is dismiss the ActionSheet, which you could do with dismissWithClickedButtonIndex:animated:

like image 116
ttarik Avatar answered Oct 11 '22 19:10

ttarik


Adding this method worked for me:

    -(void) dismissActionSheet:(id)sender {
        UIActionSheet *actionSheet =  (UIActionSheet *)[(UIView *)sender superview];
        [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
    }
like image 39
hypermiler Avatar answered Oct 11 '22 18:10

hypermiler


action sheet scope problem.

used [actionSheet dismissWithClickedButtonIndex:0 animated:YES];

like image 4
Iqbal Khan Avatar answered Oct 11 '22 20:10

Iqbal Khan