Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertView Button Action

How can I use two actions for UIButton click?I have a UIAlertView showing with two button.Play again and exit.Now i want to execute two method in the click event of these buttons.

like image 801
sohel14_cse_ju Avatar asked Apr 23 '11 10:04

sohel14_cse_ju


People also ask

What is UIAlertView?

A view that displays an alert message.


1 Answers

UPDATE - May 2016

UIAlertView is deprecated. You can now use UIAlertController as explained here.

Old Answer with UIAlertView

  1. You can create a UIAlertView like this

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Really reset?"                            message:@"Do you really want to reset this game?"                            delegate:self                            cancelButtonTitle:@"Cancel"                            otherButtonTitles:@"reset", nil];  [alert show]; 
  2. To handle AlertView button click, you have to conform to UIAlertViewDelegate protocol.

    @interface YourViewController:UIViewController<UIAlertViewDelegate>{   .......   ....... } 
  3. Then implement UIAlertViewDelegate protocol methods,

    - (void)alertView:(UIAlertView *)alertView                     clickedButtonAtIndex:(NSInteger)buttonIndex{     if (buttonIndex == [alertView cancelButtonIndex]){       //cancel clicked ...do your action     }else{       //reset clicked     } } 
like image 166
Krishnabhadra Avatar answered Sep 22 '22 15:09

Krishnabhadra