2 UIAlertView 有 3 个按钮?

发布于 2024-10-17 18:13:04 字数 75 浏览 1 评论 0原文

我想知道如何制作 2 个 UIAlertView,带有 3 个按钮,UIAlertViews(2) 需要不同,选项和操作...如何???

I wanna know how can I make 2 UIAlertView, with 3 buttons, the UIAlertViews(2) needs be different, the options and the actions... how ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

狼亦尘 2024-10-24 18:13:04

试试这个:

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

Try this:

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

then do the same for the next alertView, just change the tag to 2

Then just run this method

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

Also - make sure you include the UIAlertViewDelegate

你げ笑在眉眼 2024-10-24 18:13:04

只需检查alertviews(4)委托方法中的2,哪个alertviews负责调用该方法(1)。

Just check 2 in the alertviews(4) delegate method which alertviews was responsible for the method to be called(1).

青衫负雪 2024-10-24 18:13:04

UIAlertview delegates在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 警报

UIAlertview delegates are deprecated in ios 9.0

Also when you add more then 2 buttons, they will be vertically assigned by IOS.

you can do with simply 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文