Detecting button pressed when there are multiple alert views Detecting button pressed when there are multiple alert views ios ios

Detecting button pressed when there are multiple alert views


It would be more technical as well better that set unique tag for separate UIAlertView and identify it and access in its delegate method.

For example,

    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Message" message:@"Are You Sure you want to Update?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok",nil];    [alert setTag:1];    [alert show];    [alert release];    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex      {        if(alertView.tag == 1)        {            // set your logic        }    }


Use tag property to uniquely identify each of the alertview u create.

Like this

myAlertView.tag = 1

Then in the clickedButtonAtIndex delegate method check which alertview's button was clicked using this tag property ,

if(alertView.tag==1)


I wouldn't use the titles to distinguish between the buttons. You'll run into problems when your app is localized or you decide to change the button titles, but forget to update them everywhere. Use the button indexes instead or if you only have one button in addition to a cancel button, use the cancelButtonIndex property of UIAlertView.

To distinguish between multiple alert views, you could use their tag property.


matomo