Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine which UIAlertView called the delegate.

In the alertView delegate, theres a method:

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

My question is, how can I find which AlertView called this delegate.

For example, I have a couple alert views which all use the delegate, but depending on which alertview called this method, I want to set up different actions for buttonIndex's.

like image 912
theNoobProgrammer Avatar asked Oct 06 '11 17:10

theNoobProgrammer


1 Answers

The "alertView" object that is being passed into the method is the actual alert that is being used in the method. The most straightforward way is to provide logic inside this method that looks at the alertView object (maybe looking at the name or tag? It's up to you), and then provides different actions for each.

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
  if (alertView.tag == 1)
  {
    // do something
  }
  else if (alertView.tag == 2)
  {
    // do something else
  }

  // continue for each alertView

}
like image 186
5StringRyan Avatar answered Sep 28 '22 13:09

5StringRyan