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;
}
ttarik
All you need to do is dismiss the ActionSheet, which you could do with dismissWithClickedButtonIndex:animated:
Adding this method worked for me:
-(void) dismissActionSheet:(id)sender {
UIActionSheet *actionSheet = (UIActionSheet *)[(UIView *)sender superview];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
Iqbal Khan
action sheet scope problem.
used [actionSheet dismissWithClickedButtonIndex:0 animated:YES];
来源:https://stackoverflow.com/questions/5726408/how-to-dismiss-action-sheet