How can I skip a ViewController when dismissing fr

2019-09-04 03:35发布

Say that you have some ViewControllers like:

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

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) }

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.

Any ideas?

1条回答
三岁会撩人
2楼-- · 2019-09-04 04:13

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
                        }
                    }
        }
查看更多
登录 后发表回答