HOW TO IDENTIFY UIACTIONSHEET BUTTON IN OBJECTIVE-C?

Pooja Malohtra

Total Post:47

Points:331
Posted by  Pooja Malohtra
 776  View(s)
Ratings:
Rate this:

I have created an UIActionSheet using below code in our iPhone application:

UIActionSheet *actionSheet = [[UIActionSheet alloc]
                               initWithTitle:@"ActionSheetSample"
                               delegate:self
                               cancelButtonTitle:@"Cancel"
                               destructiveButtonTitle:nil
                               otherButtonTitles:@"Button1",@"Button2",@"Button3", nil];
[actionSheet showInView:self.view];

Now, my action sheet created successfully but my problem is how can I identify which button is clicked.!
Please help me!

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: How to identify UIActionSheet button in Objective-C?

    UIActionSheet provides a delegate method actionSheet:clickedButtonAtIndex: when the user clicks a button on an action sheet.
    For Example:

    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
      if(buttonIndex == 0)
      {
         NSLog(@"First Button is Clicked");
      }
      else if(buttonIndex == 1)
      {
         NSLog(@"Second Button is Clicked");
      }
    }

    Above method have two parameters actionSheet and buttonIndex.
    actionsheet: contains the action button, and
    buttonIndex have the button indices which will start at 0.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!