2 UIAlertView one by one

I have 2 UIAlert that is displayed, I press the button. I want the second warning to appear only when the first UIAlert was fired, when we clicked the first OK button.

How do I proceed? 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];
}
+3
source share
1 answer

Use different tags for two types of viewing.

alertView.tag = 1000; 

Inject the delegate method of the alert view and check the tag value. When a delegate is called with the first warning view, create and show the second warning view.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if(alertView.tag == 1000)
    {
        //first alert view 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 button action
    }

}
+5
source

Source: https://habr.com/ru/post/1759856/


All Articles