使用Swift 3在两个故事板之间移动时,导航栏将消失

使用Swift 3在两个故事板之间移动时,导航栏将消失,swift,xcode,swift3,xcode8,Swift,Xcode,Swift3,Xcode8,我正在从事的项目目前有多个故事板。我们正在使用以下代码以编程方式从第一个故事板移动到下一个故事板: let storyboard = UIStoryboard(name: "Main", bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: "DiscoverViewController") as UIViewController self.presen

我正在从事的项目目前有多个故事板。我们正在使用以下代码以编程方式从第一个故事板移动到下一个故事板:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "DiscoverViewController") as UIViewController
            self.present(vc, animated: true, completion: nil)
它要移动到的情节提要将情节提要入口点指向上面正在实例化和显示的视图控制器的导航控制器

问题是当显示页面时,导航栏不会出现。它出现在情节提要视图中,在我们分离情节提要之前,我们没有这个问题

我从一个故事板到另一个故事板的方式有问题吗?我是否需要显示导航控制器而不是视图控制器


谢谢

这是因为您正在显示视图控制器,而您可能希望将其推送到导航堆栈上

答案表明你需要做什么。以下是根据您的示例改编的代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "DiscoverViewController") as UIViewController
self.navigationController?.pushViewController(vc, animated: true)

这是因为您正在呈现视图控制器,而您可能希望将其推送到导航堆栈上

答案表明你需要做什么。以下是根据您的示例改编的代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "DiscoverViewController") as UIViewController
self.navigationController?.pushViewController(vc, animated: true)

您的第二个控制器不是NavigationController。因此,您将显示一个ViewController并“隐藏”导航栏。您需要推送新控制器(不显示)以保留导航栏。您的第二个控制器不是NavigationController。因此,您将显示一个ViewController并“隐藏”导航栏。您需要按下新控制器(不显示)以保持导航栏。