16

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

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

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

[self dismissModalViewControllerAnimated:YES];

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

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

这里有什么问题..

4

3 回答 3

31

添加了 iOS 6 和 pre-iOS 6 的答案:

iOS 5.0 及更高版本

当您注销时,请在关闭之前添加此检查:

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

iOS 4.X 及更低版本

在解雇之前添加此检查:

if (![[self modalViewController] isBeingDismissed])
{
    [self dismissModalViewControllerAnimated:YES];
}
于 2013-06-27T17:44:30.883 回答
3

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

if (![[self modalViewController] isBeingDismissed])
{
   [self dismissModalViewControllerAnimated:YES];
}
于 2013-04-08T09:47:50.893 回答
1

有很多事情可能会导致这种情况,这里有一些选项:

  1. 您忘记在 ViewController 方法之一(例如 viewWillAppear、viewWillAppear 等)上调用 super。请参阅 UIViewController 文档以了解何时必须调用 super。
  2. 多次调用dismissModalViewControllerAnimated: 方法,如果您多次将目标添加到UIButton,就会发生这种情况。

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

于 2013-04-08T10:06:43.433 回答