如何从 TabbarController 继续查看控制器?

How to segue to view controller from TabbarController?

我有一个 TabbarController,它是我的 app.So 的入口点,我想将此 TabbarController 转至 ViewControllerA。我执行performSegue(with: "identifier")。我可以达到ViewControllerA,但是当我达到ViewControllerA时没有NavigationBar

我试图将 ViewControllerA 嵌入到 NavigationController 1st 中,所以故事板看起来像这样

TabbarController-> NavigationController -> ViewControllerA

通过这个,我可以达到 ViewControllerA.But 我在 prepareForSegue 中有问题 method.Cause 我需要在 segue 中包含一个值,现在似乎没有包含该值。

我在 prepareForSegue 中的代码是这样的:

if let VcA = segue.destination.navigationController?.topViewController as? ViewControllerA {
  VcA.postId = sender as! Int
}else{
   print("cant work")
}

我还尝试将 tabbarController 嵌入到 NavigationController 中,但在 Xcode-> Editor -> Embed 中该选项被禁用。

所以我的问题是

如何从 TabbarController 转到 ViewController 并且在目标位置 NavigationBar 可见并且可以返回到上一屏幕?

假设您的故事板类似于:

那是因为您在 TabbarController 中调用 performSegue(with: "identifier") 不是 直接连接到 segue。你应该怎么做才能在连接到导航控制器(ViewControllerA)的第一个视图控制器中实现它。所以,它会是 - 例如 - 是这样的:

class ViewControllerA: UIViewController {
    // ...

    override func viewDidLoad() {
        super.viewDidLoad()

        performSegue(with: "identifier")

    }

    // ...
}

因此你的 segue 应该是从 ViewControllerA 到所需的视图控制器。