ios 在演示或关闭正在进行时尝试从视图控制器中关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15875538/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 23:05:49  来源:igfitidea点击:

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

iphoneiosobjective-cuiviewcontroller

提问by Harish

I have TWO UIViewControllerclasses, where in FirstClassi have an UIButtonfor Login, when user taps on button, i will display SecondClass... For that i have done,

我有两个UIViewController类,其中FirstClass有一个UIButtonfor Login,当用户点击按钮时,我将显示SecondClass......为此我已经完成了,

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

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

在 SecondClass 我有一个注销按钮,它将重定向到FirstClass,因为我已经完成了,

[self dismissModalViewControllerAnimated:YES];

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

当我在 SecondClass 中按下注销按钮时,我收到警告消息

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

What is the problem here..

这里有什么问题..

回答by Kevin Zych

Added both iOS 6 and pre-iOS 6 answers:

添加了 iOS 6 和 iOS 6 之前的答案:

iOS 5.0 and later

iOS 5.0 及更高版本

When you logout, add this check before dismissing:

当您注销时,在解除之前添加此检查:

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

iOS 4.X and less

iOS 4.X 及以下

Add this check before dismissing:

在解雇之前添加此检查:

if (![[self modalViewController] isBeingDismissed])
{
    [self dismissModalViewControllerAnimated:YES];
}

回答by Vishal

Call these lines where you logout & then check:

在您注销的地方调用这些行,然后检查:

if (![[self modalViewController] isBeingDismissed])
{
   [self dismissModalViewControllerAnimated:YES];
}

回答by Tom Susel

There are many things that may cause this, here are some options:

导致这种情况的原因有很多,这里有一些选择:

  1. You forgot to call super on one of the ViewController methods such as viewWillAppear, viewWillAppear etc. Consult the UIViewController documentation to see when you have to call super.
  2. The dismissModalViewControllerAnimated: method is being called more than once, this can happen if you added a target to the UIButton more than once.
  1. 您忘记在 ViewWillAppear、viewWillAppear 等 ViewController 方法之一上调用 super。请参阅 UIViewController 文档以了解何时必须调用 super。
  2. DismissModalViewControllerAnimated: 方法被多次调用,如果您多次向 UIButton 添加目标,就会发生这种情况。

To get better understanding of the problem please paste the code of both view controllers in its entirety.

为了更好地理解问题,请完整粘贴两个视图控制器的代码。