首页 文章

解雇模态提出的VC和Popping呈现VC

提问于
浏览
0

我有 viewcontroller 嵌入 navigationcontroller ,将另一个 viewcontroller 推入堆栈 . 这推 viewcontroller 有一个 embedded viewcontroller ,它是segues / modally呈现的最终 viewcontroller .

在按钮上单击,我试图解除最终呈现的 viewcontroller 并弹出当前的 viewcontroller 并返回初始状态 .

到目前为止,我已经能够解雇了,但是弹出似乎不适用于解雇的完成处理程序 .

我已经尝试打印出层次结构,即 self.presentingViewControllerself.navigationControllerself.presentingViewController.presentingViewController ......,所有这些都输出为nil,而且我现在无法恢复到初始状态 .

在查看视图层次结构时,最终呈现的 viewcontroller 位于 UITransitionView 之下,与我之前提到的堆栈的其余部分分开 .

任何想法/指导将不胜感激 .

2 回答

  • 0

    既然你提到segues我认为unwind segues可能会有所帮助 . 我构建了一个快速测试项目,它们确实在您的场景中正常运行 .

    在相关的SO问题中有一个相当优秀的答案What are Unwind segues for and how do you use them? . 针对您的特定情况的答案摘要是:将以下函数放在初始视图控制器中:

    @IBAction func unwindToThisViewController(segue: UIStoryboardSegue)
    {
    }
    

    然后,您可以直接使用Storyboard Segues(如引用的答案中)直接“展开”到该视图控制器,或者通过以下方式编程:

    self.performSegue(withIdentifier: "unwindToThisViewController", sender: self)
    

    还有一篇很好的文章,名为Working with Unwind Segues Programmatically in Swift,详细介绍了很多 .

  • 0

    你能试一下吗

    if let nav = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController {
    
         self.dismiss(animated:true) {
    
            nav.popToRootViewController(animated:true)
         }
     }
    

相关问题