开发者

2 UIAlertView one after the other

开发者 https://www.devze.com 2023-01-11 13:14 出处:网络
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.

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];
}


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
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号