0

I have to show multiple UIAlerts in one viewController before iOS8 we can use the UIAlerts with tags and we can identify in clickedButtonAtIndex using tags like.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag == 1)
{
//UIAlert1 button clicked
}

if(alertView.tag == 2)
{
//UIAlert2 button clicked
}
}

so we can do stuff. how to identify button clicks of different UIAlertControllers. Because one alert1 button click i have to change the some text color and alert2 button click i have to pop the view controller.

Logger
  • 1,274
  • 1
  • 14
  • 25

2 Answers2

1

UIAlertController is block-based.

Create an UIAlertAction instance for each action and pass the block to be executed after the button is tapped.

For further information read the UIAlertController "review" of Mattt Thompson.

vadian
  • 274,689
  • 30
  • 353
  • 361
  • Yes i can pass the block to be executed for the button action. Like i have two alerts with buttons like cancel and done, cancel and save. When user click on done i have to do one functionality and when user click on save i have to do other functinality. – Logger Oct 16 '15 at 05:12
0

You can do the following way.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
  if(alertView.tag == 1)
    {
      //UIAlert1 button clicked
         if(buttonIndex==0){//say, **Cancel** button tag
            //alert2 "Cancel" button has tapped
          }else if(buttonIndex==1){say, **OK** button tag
            //alert2 "OK" button has tapped
           }
    }

  if(alertView.tag == 2)
    {
      //UIAlert2 button clicked
      if(buttonIndex==0){//say, **Yes** button tag
           //alert2 "YES" button has tapped
          }
    }
}
Jamil
  • 2,977
  • 1
  • 13
  • 23
  • This delegate method is for use with UIAlertView, though isn't used with UIAlertController, which has taken over from UIAlertview and UIActionSheet as from iOS8 – Jim Tierney Oct 15 '15 at 19:42
  • @jamil65able From iOS8 onwards we cant use the UIAlertView. – Logger Oct 16 '15 at 05:08