12
votes

Ajouter trois boutons dans un uialertview

J'ai créé uialertview et ajoutez deux boutons, maintenant, je dois ajouter un bouton de plus en vue d'alerte. Comment modifier mon code pour ajouter un bouton de plus? XXX


0 commentaires

6 Réponses :


3
votes

Essayez d'ajouter vos boutons dans les autresButtontiTles xxx


1 commentaires

Bonjour Buildsuited, merci pour votre réponse. Vraiment ça marche bien.



35
votes

Si vous avez vraiment du mal à trouver la solution, le code suivant peut vous aider.

UIAlertView *alert = [[UIAlertView alloc] 
                        initWithTitle:@"Refresh" 
                              message:@"Are you want to Refresh Data" 
                             delegate:self 
                    cancelButtonTitle:@"Cancel" 
                    otherButtonTitles:@"OK", @"Done", nil];
[alert show];
[alert release];


2 commentaires

Si vous voulez toucher, obtenez un iPhone ou probablement un iPod Touch


UialertView obsolète dans IOS 9.0. S'il vous plaît utiliser uialertController.



11
votes

Vous pouvez également faire votre classe le délégué de UialertviewDelegate et atteindre tous vos boutons "Fonctionnalités en le faisant;

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        //
    }
    else if (buttonIndex == 1) {
        //
    }
    else if (buttonIndex == 2) {
        //
    }
    else if (buttonIndex == 3) {
        //
    }
}


0 commentaires

3
votes

dans iOS11 / SWIFT 4, c'est aussi simple que ceci: xxx


0 commentaires

1
votes

Essayez ceci:

UIAlertController * alert=   [UIAlertController
                              alertControllerWithTitle:@"Refresh"
                              message:@"Are you want to Refresh Data" 
                           preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* cancel = [UIAlertAction
                         actionWithTitle:@"Cancel"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             // code here...
                         }];

UIAlertAction* ok = [UIAlertAction
                         actionWithTitle:@"Ok"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             // code here...
                         }];

UIAlertAction* done = [UIAlertAction
                         actionWithTitle:@"Done"
                         style:UIAlertActionStyleDefault
                         handler:^(UIAlertAction * action)
                         {
                             // code here...
                         }];

[alert addAction:ok] ;
[alert addAction:done];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];


1 commentaires

Code Seules les réponses ne sont pas encouragées car elles ne fournissent pas beaucoup d'informations pour les futurs lecteurs, veuillez fournir une explication à ce que vous avez écrit



0
votes
let alert = UIAlertController(title: "title",
                                      message: "message",
                                      preferredStyle: .alert)

        alert.addAction(UIAlertAction(title: "Restore Purchases", style: .default, handler: {(action: UIAlertAction!) in

            //function to execute when button is clicked

        }))

        alert.addAction(UIAlertAction(title: "Subscribe", style: .default, handler: {(action: UIAlertAction!) in

            //function to execute when button is clicked

        }))

        alert.addAction(UIAlertAction(title: "Cancel", style: .destructive, handler: {(action: UIAlertAction!) in

            //function to execute when button is clicked
        }))

        self.present(alert, animated: true, completion: nil)

0 commentaires