Reputation: 606
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];
}
Upvotes: 3
Views: 2327
Reputation: 10475
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
}
}
Upvotes: 5