Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add three Buttons in an UIAlertView

I created uialertview, and add two buttons, Now I need to add one more button in alert view. How to edit my code to add one more button?

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Refresh" message:@"Are you want to Refresh Data" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
like image 209
Velmurugan Avatar asked Dec 21 '10 06:12

Velmurugan


2 Answers

In iOS11 / Swift 4, it is as simple as this:

let alert = UIAlertController(title: "Saving Demo.", message: "Do you wish to save this Demo Settings?", preferredStyle: .alert)
            let OKAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: {
                (_)in
                //SAVE DEMO DATA HERE       
            })
            let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default, handler: {
                (_)in
                //do something
            })
            let thirdAction = UIAlertAction(title: "3rd Btn", style: UIAlertActionStyle.default, handler: {
                (_)in
                //do another thing
            })
            alert.addAction(OKAction)
            alert.addAction(cancelAction)
            alert.addAction(thirdAction)
            self.present(alert, animated: true, completion: nil)
like image 66
Josh Avatar answered Oct 24 '22 21:10

Josh


Try This:

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];
like image 21
Nick Avatar answered Oct 24 '22 21:10

Nick