呈现模态叠加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 (将#修改为@)