从 navigationController 解散时如何跳过 ViewController? [英] How can I skip a ViewController when dismissing from navigationController?

查看:25
本文介绍了从 navigationController 解散时如何跳过 ViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您有一些 ViewController,例如:

Say that you have some ViewControllers like:

A --> B --> C --> X --> D

其中 X 是某种可以从任何地方打开的永久菜单.所有这些都插入到 NavigationController 中,因此返回时我会执行以下操作:

Where X is some sort of perpetual menu that can be opened from everywhere. All of those are plugged to a NavigationController, so for going back I would do something like:

func leftNavButtonClick(sender: UIButton) {navigationController?.popViewControllerAnimated(true)}

但是,如果我从 D 开始这样做,我想回到 C,而不是 X.我尝试在打开下一个 ViewController 之前关闭菜单,但这似乎效果不佳.

However if I do that from D, I want to go back to C, not X. I tried dismissing the menu before opening the next ViewController but that doesn't seem to work very well.

有什么想法吗?

推荐答案

您可以使用视图控制器堆栈找到您的 VC 并弹出它

You can use the view controller stack to find your VC and pop to it

if let vcStack = self.navigationController?.viewControllers
        {
            for vc in vcStack {
                        if vc.isKindOfClass(MyVC)
                        {                           
                            self.navigationController?.popToViewController(vc, animated: true)
                            break
                        }
                    }
        }

这篇关于从 navigationController 解散时如何跳过 ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆