user627441
user627441

Reputation: 13

UIAlertview in 2 view

I have a alertview that starts in a view A and must stop in view B. How can I stop the alertview on B?

thks

Upvotes: 0

Views: 207

Answers (2)

WrightsCS
WrightsCS

Reputation: 50697

How are you moving from A to B while a UIAlertView is displayed? Maybe post some code.

This scenario does not seem user-friendly, but there is a way you can dismiss the alert from A in B.

View A

Create an NSNotificationCenter and point it to a method that dismisses the alert:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissAlert) name:@"dismissAlert" object:nil];

And the notification should call something like the following:

- (void) dismissAlert:(NSNotification *)notification
{
    [alertView dismissWithClickedButtonIndex: 0 animated: YES];
}

View B

Now when you want to dismiss the alert, call the notification you created in View A:

[[NSNotificationCenter defaultCenter] postNotificationName:@"dismissAlert" object:nil];

Upvotes: 1

adpalumbo
adpalumbo

Reputation: 3031

Use dismissWithClickedButtonIndex:animated:

Upvotes: 0

Related Questions