views:

62

answers:

1

Hi,

I have an 2 UIAlert which is displayed I press on a button. I want the 2nd alert to be visible only when the first UIAlert is dismissed that is when we have pressed the first OK button.

How should I proceed please? Below is my code:

- (IBAction)button:(id)sender {
 UIAlertView *view;
 view = [[UIAlertView alloc]
   initWithTitle: @"Message"
   message: @"Adding..."
   delegate: self
   cancelButtonTitle: @"OK" otherButtonTitles: nil];
 [view show];

 MyAppAppDelegate *appDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];

 if (appDelegate.array_presets.count) {
  view = [[UIAlertView alloc]
    initWithTitle: @"Message"
    message: @"limit already reached"
    delegate: self
    cancelButtonTitle: @"OK" otherButtonTitles: nil];
  [view show];
 }

 [view autorelease];
}
+1  A: 

Use different tags for your two alert views.

alertView.tag = 1000; 

Implement the alert view delegate method and check for the tag value. When the delegate gets called with the first alert view create and show the second alert view.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 1000)
    {
        //first alert view's button clicked
        UIAlertView *view = [[UIAlertView alloc]
                initWithTitle: @"Message"
                message: @"limit already reached"
                delegate: self
                cancelButtonTitle: @"OK" otherButtonTitles: nil];
        view.tag = 2000;
        [view show];
    }
    if(alertView.tag == 2000)
    {
        //handle second alert view's button action
    }

}
lukya
You probably meant to use `if(alertView.tag != 1000)` in the second "if" or check for another value like 1001.But that doesn't solve the posters problem, I think.
DarkDust
Thanks for the correction. Edited the code in the answer. I think this should solve the problem as he wants to show the second alert view after the first one is dismissed.
lukya