2011-02-16 101 views
0

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

+0

你有什么已经尝试过?实现这个问题到底有什么问题? – Vladimir 2011-02-16 21:42:38

回答

8

试试这个:

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

+1

完美之一... – 2011-03-05 11:37:58

0

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

0

UIAlertview代表已在i中弃用os 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