2011-02-16 73 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