2 UIAlertView с 3 кнопками? - PullRequest
       24

2 UIAlertView с 3 кнопками?

0 голосов
/ 17 февраля 2011

Я хочу знать, как я могу сделать 2 UIAlertView, с 3 кнопками, UIAlertViews (2) должны быть разными, параметры и действия ... как ???

Ответы [ 3 ]

8 голосов
/ 05 марта 2011

Попробуйте это:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Message." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:@"Button 2", @"Button 3", nil];
alert.tag = 1;               
[alert show];

затем сделайте то же самое для следующего alertView, просто измените тег на 2

Тогда просто запустите этот метод

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
     if(alert.tag == 1) {
          //the alert tag 1 was just closed - do something
     }
}

Также - убедитесь, что вы включили UIAlertViewDelegate

0 голосов
/ 08 июня 2016

UIAlertview делегаты устарели в IOS 9.0

Также, когда вы добавите более 2 кнопок, они будут назначаться IOS по вертикали.

вы можете сделать просто с помощью UIAlertController

UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:[[[NSBundle mainBundle] infoDictionary]
                                                            objectForKey:@"CFBundleDisplayName"]
                                  message:@"share via"
                                  preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* fbButton = [UIAlertAction
                                actionWithTitle:@"Facebook"
                                style:UIAlertActionStyleDefault
                                handler:^(UIAlertAction * action)
                                {
                                    // Add your code
                                }];
    UIAlertAction* twitterButton = [UIAlertAction
                                   actionWithTitle:@"Twitter"
                                   style:UIAlertActionStyleDefault
                                   handler:^(UIAlertAction * action)
                                   {
                                       // Add your code

                                   }];
    UIAlertAction* watsappButton = [UIAlertAction
                                    actionWithTitle:@"Whatsapp"
                                    style:UIAlertActionStyleDefault
                                    handler:^(UIAlertAction * action)
                                    {
                                      // Add your code
                                    }];
    UIAlertAction* emailButton = [UIAlertAction
                                    actionWithTitle:@"Email"
                                    style:UIAlertActionStyleDefault
                                    handler:^(UIAlertAction * action)
                                    {

                                        // Add your code
                                    }];
    UIAlertAction* cancelButton = [UIAlertAction
                                  actionWithTitle:@"Cancel"
                                  style:UIAlertActionStyleDefault
                                  handler:^(UIAlertAction * action)
                                  {
                                      //Handel no, thanks button

                                  }];

    [alert addAction:fbButton];
    [alert addAction:twitterButton];
    [alert addAction:watsappButton];
    [alert addAction:emailButton];
    [alert addAction:cancelButton];

    [self presentViewController:alert animated:YES completion:nil];

IOS 9 Alert with vertical buttons

0 голосов
/ 17 февраля 2011

Просто отметьте 2 в методе делегата alertviews (4), который alertviews отвечал за вызываемый метод (1).

...