Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to dismiss from view controller while a presentation or dismiss is in progress

I have TWO UIViewController classes, where in FirstClass i have an UIButton for Login, when user taps on button, i will display SecondClass... For that i have done,

SecondClass *index = [[SecondClass alloc] init];
[self presentModalViewController:index animated:YES];

In SecondClass i have a logout button, which will redirect to FirstClass, for that i have done,

[self dismissModalViewControllerAnimated:YES];

When i press Logout button in SecondClass, i get the warning msg

**Attempt to dismiss from view controller <FirstClass: 0e39w88e160> while a presentation or dismiss is in progress!**

What is the problem here..

like image 363
Harish Avatar asked Apr 08 '13 09:04

Harish


2 Answers

Added both iOS 6 and pre-iOS 6 answers:

iOS 5.0 and later

When you logout, add this check before dismissing:

if (![self.presentedViewController isBeingDismissed])
{
    [self dismissModalViewControllerAnimated:YES completion:nil];
}

iOS 4.X and less

Add this check before dismissing:

if (![[self modalViewController] isBeingDismissed])
{
    [self dismissModalViewControllerAnimated:YES];
}
like image 189
Kevin Zych Avatar answered Sep 28 '22 00:09

Kevin Zych


Call these lines where you logout & then check:

if (![[self modalViewController] isBeingDismissed])
{
   [self dismissModalViewControllerAnimated:YES];
}
like image 29
Vishal Avatar answered Sep 27 '22 23:09

Vishal