Je veux afficher UIActionSheet au-dessus de l'UIAlertView. Mais selon le code ci-dessous, il sera caché de UIAlertView. (Voir ci-dessous capture d'écran) comment afficher UIActionSheet sur le UIAlertView dans l'objectif c
D'abord, je montre la UIAlertView personnalisée et lorsque les unités de prise d'utilisateur, puis afficher le UIActionSheet. Mais il est caché de UIAlertView. Voici mon jeu de code.
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet.tag == 2) {
return;
}
if (actionSheet.tag == 1 && (int)buttonIndex == 4) {
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 310, 60)];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(5,0,100,25)];
label1.text = @"Dimensions:";
[v addSubview:label1];
UITextField *textField1 = [[UITextField alloc] initWithFrame:CGRectMake(100,0,60,25)];
textField1.borderStyle = UITextBorderStyleRoundedRect;
textField1.placeholder = @"Width";
textField1.keyboardAppearance = UIKeyboardAppearanceAlert;
[textField1 setValue:[UIFont fontWithName: @"San Francisco" size:12] forKeyPath:@"_placeholderLabel.font"];
textField1.delegate = self;
[v addSubview:textField1];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(172,0,25,25)];
label.text = @"X";
[v addSubview:label];
UITextField *textField3 = [[UITextField alloc] initWithFrame:CGRectMake(195,0,60,25)];
textField3.placeholder = @"Height";
textField3.borderStyle = UITextBorderStyleRoundedRect;
textField3.keyboardAppearance = UIKeyboardAppearanceAlert;
[textField3 setValue:[UIFont fontWithName: @"San Francisco" size:12] forKeyPath:@"_placeholderLabel.font"];
textField3.delegate = self;
[v addSubview:textField3];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(5,30,50,25)];
label2.text = @"Units:";
[v addSubview:label2];
UITextField *textField4 = [[ReadOnlyTextField alloc] initWithFrame:CGRectMake(100,30,155,25)]; //145
textField4.placeholder = @"-- Select an Unit --";
textField4.borderStyle = UITextBorderStyleRoundedRect;
textField4.keyboardAppearance = UIKeyboardAppearanceAlert;
[textField4 setValue:[UIFont fontWithName: @"San Francisco" size:12] forKeyPath:@"_placeholderLabel.font"];
[textField4 addTarget:self action:@selector(selectUnit:) forControlEvents:UIControlEventTouchDown];
textField4.delegate = self;
[v addSubview:textField4];
av = [[UIAlertView alloc] initWithTitle:@"Dimensions" message:@"" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"Download", nil];
[av setValue:v forKey:@"accessoryView"];
[av show];
}
-(void)selectUnit:(id)sender
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select an option" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.tag = 2;
[actionSheet addButtonWithTitle:@"Pixels"];
[actionSheet addButtonWithTitle:@"Inches"];
[actionSheet addButtonWithTitle:@"Centimetres"];
[actionSheet addButtonWithTitle:@"Millimetres"];
[actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet showInView:self.view]; //[UIApplication sharedApplication].keyWindow.rootViewController.view
}
Alors, comment puis-je afficher UIACtionSheet au-dessus du UIAlertView personnalisé ????
Pouvez-vous expliquer le flux exact de votre code? Je pense d'abord que vous avez appelé UIActionSheet alors la réponse pour UIActionsheet est UIAlertView et sur l'action UIAlertView vous voulez montrer une nouvelle UIActionSheet. –
@SiddheshMhatre D'abord, j'ouvre UIActionSheet, puis je sélectionne une option. lorsque vous sélectionnez une option, il sera ouvert personnalisé UIAlertView. Après cela, lorsque je sélectionne un champ de texte personnalisé sur UIAlertView (champ unité), ouvrez à nouveau la feuille UIActionSheet. Cette UIActionSheet est cachée de l'UIAlerView précédente (voir l'image ci-jointe). –