iphone - 在演示或解散过程中尝试从 View Controller 中解散

标签 iphone ios objective-c uiviewcontroller

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

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

在 SecondClass 中我有一个logout 按钮,它将重定向到 FirstClass,因为我已经这样做了,

[self dismissModalViewControllerAnimated:YES];

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

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

这里有什么问题..

最佳答案

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

iOS 5.0 及更高版本

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

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

iOS 4.X 及更低版本

在解散之前添加此检查:

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

关于iphone - 在演示或解散过程中尝试从 View Controller 中解散,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15875538/

相关文章:

iphone - 我正在重新制作一个小应用程序,以更好地在iOS上使用MVC模式。

iphone - ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering 的代码示例?

android - Flutter 如何在没有任何用户交互的情况下从一个页面导航到另一个页面

objective-c - 如何在对象内使用 objc_setAssociatedObject/objc_getAssociatedObject?

objective-c - NSCollectionViewItem不显示自定义 View

objective-c - UIView 类别和属性

iphone - Apple Watch 与 iPhone 的连接状态

ios - 如何在 Objective-C 中引用嵌套的 JSON 键

ios - 使用平板电脑模拟器时的未知填充

objective-c - 释放属性(property)(Objective-C)