无法关闭嵌入在导航控制器中的视图控制器 [英] Can't dismiss View Controller that's embedded in a Navigation Controller

查看:36
本文介绍了无法关闭嵌入在导航控制器中的视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下场景.嵌入在导航控制器中的视图控制器.

I have the following scenario. A view controller that's embedded in a navigation controller.

这个视图控制器有一个按钮,它实例化一个标签栏控制器,然后显示它的一个视图控制器.

This view controller has a button that instantiate a tab bar controller, then presents one of its view controllers.

当我关闭标签栏控制器提供的控制器时,我总是在初始视图控制器中结束,在它的同一个实例中.

When i dismiss the controller presented by the tab bar controller, i always end up in the initial view controller, in the same instance of it.

我尝试的是:

    func showHomeScreen()  {
    //trying to dismiss the current view controller ( will move this code out of this method once i figure out how to do it
    self.navigationController?.popViewController(animated: true)
    self.dismiss(animated: true, completion: nil)
    //showing the next view controller
    let tabBarController = storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController

    tabBarController.selectedViewController = tabBarController.viewControllers?[1]
    present(tabBarController, animated: true, completion: nil)
}

self.navigationController?.popViewController => 返回 nilself.dismiss(animated: true, completion: nil) 似乎没有做任何事情.

self.navigationController?.popViewController => returns nil self.dismiss(animated: true, completion: nil) doesn't seem to do anything.

谁能告诉我如何解决这个问题,我想它非常简单,但我找不到答案.

Can anyone please tell me how to fix this, i imagine its something terribly simple but i can't find the answer to it.

这是我的故事板的样子:

This is how my storyboard looks:

https://pasteboard.co/HVdHp6P.png

https://pasteboard.co/HVdHHoG.png

推荐答案

正如我在你的代码中看到的那样.

As i can see in your code.

A"VC 是B"的父级.风险投资

"A" VC is a parent of "B" VC

A"VC 不能出现B"VC,在你解散A"之后风险投资.

"A" VC can't present "B" VC, after you dismiss "A" VC.

我认为正确的方法是:

1.制作C"作为A"的父级和B"

1.make "C" as the parent of "A" and "B"

2.制作A"、B"在相同级别的视图层次结构中,

2.make "A", "B" in the same level of view hierarchy,

然后是C"出现A",A"在C"之后解雇自己现在的B"

and then, "C" present "A", "A" dismiss itself, after that "C" present "B"

这篇关于无法关闭嵌入在导航控制器中的视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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