2011-04-20 8 views
11

He utilizado este código para mostrar UIPicker en uiactionsheet pero cuando hago clic en el botón de cierre Quiero quitar la hoja de acción de la vista. Entonces, ¿cuál debería ser el código para eliminar la vista del formulario de ActionSheet?cómo despedir Hoja de acción

- (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; 
} 
+0

he utilizado [actionsheet removeFromSuperview] ; pero no está funcionando. –

+0

ver http://stackoverflow.com/questions/1551587/how-to-dismiss-uiactionsheet-automatically –

Respuesta

11

Todo lo que necesita hacer es descartar el ActionSheet, que usted podría hacer con dismissWithClickedButtonIndex:animated:

+0

Je, ya lo descubrió por sí mismo: P – ttarik

+0

gracias por ur agradable ayuda –

+0

¿Qué hay de Swift? – dylan

4

action sheet scope problem.

utiliza [actionSheet dismissWithClickedButtonIndex:0 animated:YES];

+0

¿Dónde se utiliza en que? Intenté crear un método dismissActionSheet y poner el [actionSheet dismissWith ...] en él, pero parece que no funciona. –

7

La adición de este método ha funcionado para mí:

-(void) dismissActionSheet:(id)sender { 
     UIActionSheet *actionSheet = (UIActionSheet *)[(UIView *)sender superview]; 
     [actionSheet dismissWithClickedButtonIndex:0 animated:YES]; 
    } 
+0

mi remitente es un UIBarButtonItem que se añade a una matriz mutable que se añade a un UIToolBar que se añade a la actionsheet como subvista. ¿Cómo accedo a la hoja de acciones en el método de descarte? – marciokoko

Cuestiones relacionadas