微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

呈现模态叠加ViewController会删除先前的视图层次结构

如何解决呈现模态叠加ViewController会删除先前的视图层次结构

我正在尝试创建一个自定义ViewController并将其用作UIAlertViewController,这意味着它将在当前ViewController显示,并且在用户按下后将被禁用好。我们称其为ErrorViewController

在所有我展示此ErrorVC的情况下,它都能正常工作,并覆盖基础ViewController。但是,只要显示ErrorVC,就会隐藏一个特定的ViewController。

用于显示ErrorVC的代码如下:

@objc static func showError(from presentingViewController: UIViewController,title: String = kErrorSomethingWentWrong,message: String? = kErrorTryAgainLater,type: ErrorViewControllerType = .message) -> ErrorViewController {
        let errorViewController = UIStoryboard.main.instantiateViewController(withIdentifier: ErrorViewController.identifier) as! ErrorViewController

        presentingViewController.modalPresentationStyle = .currentContext

        errorViewController.modalPresentationStyle = .overFullScreen
        errorViewController.modalTransitionStyle = .crossdissolve

        // Set the delegate of the dialog Box to the parentViewController
        errorViewController.delegate = presentingViewController as? ErrorViewControllerDelegate

        errorViewController.errorTitle = title
        errorViewController.errorMessage = message ?? kErrorTryAgainLater
        errorViewController.type = type

        // Present the pop up viewController from the parentViewController
        presentingViewController.present(errorViewController,animated: true)

        return errorViewController
    }

我尝试将遇到问题的definesPrersentationContext的{​​{1}}设置为true,但没有运气。调试视图层次结构时,我可以看到有问题的ViewController已从层次结构中删除,这就是为什么它不可见的原因,而在所有其他ViewController上,ViewControllers则保留在视图层次结构中

关于什么可能导致此问题的任何想法?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。