如何在 Swift 中结合 NavigationController 的两个 ViewController 之间切换

How to switch between two ViewControllers combined with a NavigationController in Swift

这是我的故事板:

在某些特定情况下,我想自动从 ScanTable (TableViewController) 切换回 StartPage。所以我添加了以下代码,在两个视图之间切换:

let startPage:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("StartPage")
self.presentViewController(startPage, animated: true, completion: nil)

所以这段代码有效,但有两个问题:

  1. StartPage 不包含导航栏。是否有可能重置导航控制器或类似的东西以使我的导航栏回到顶部?
  2. 从我的 ScanTable 到我的 StartPage 的动画不同于任何其他交换动画。我可以更改吗?

尝试使用

self.navigationController?.pushViewController(yourViewController, animated: true)

转到您要显示的视图控制器。

self.navigationController?.popToRootViewControllerAnimated(true)

如果您需要回到第一个 VC。

您可以在 appdelegate 文件上设置一些属性。

一个例子:

    UINavigationBar.appearance().barTintColor = UIColor.redColor()
    UINavigationBar.appearance().translucent = false