0

I have 2 alerts on the same page. Problem is that the clickedButtonAtIndex is answering both alerts and not just the second one. How do I separate them?

UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@"Phone Number" message:@"\n\n\n"
                                                       delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK",nil), nil];

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please Enter correct phone no." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Try Again", nil];

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {

On the first one you enter a phone number and hit ok. If it validates, great. However if it does not the second alert shows. Now when they hit "Try Again" the clickedButtonAtIndex runs on the first and second alert. I need it to only run on the second.

Rick
  • 1,153
  • 1
  • 18
  • 37

1 Answers1

0

What you have to do is give different tag to both alert view and then access by tags as:-

UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@"Phone Number" message:@"\n\n\n"
                                                       delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK",nil), nil];
passwordAlert.tag=1;

UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Please Enter correct phone no." delegate:self cancelButtonTitle:nil otherButtonTitles:@"Try Again", nil];
alert.tag=2;

- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(alert.tag==1)
    {
        if (buttonIndex==0) {

        }
        else if (buttonIndex==1) {

        }
         }
if(alert.tag==2)
    {
        if (buttonIndex==0) {

        }
        else if (buttonIndex==1) {

        }
}
Gypsa
  • 11,230
  • 6
  • 44
  • 82
  • Awesome. Thanks I am so not use to the apple docs yet. Thank you all for taking the time to answer. – Rick Aug 25 '11 at 14:28