如何在导航控制器中呈现视图控制器 SWIFT

How to present a view controller inside a navigation controller SWIFT

我有 VC1,它是一个基本的视图控制器,然后我想展示在导航控制器中的 VC2。每当我展示它时,它都不会显示导航控制器。我希望这一切都务实地完成。我用来展示 VC2 的代码是:

func matchesPressed(sender: UIButton!) {
    let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches
    self.presentViewController(matchesTVC, animated: true, completion: nil)

}

如何显示它里面的导航控制器?

实例化包含您的视图控制器的导航控制器并呈现导航控制器。

故事板中是否有导航控制器?如果是这样,给它一个故事板 ID 并用导航控制器替换你的 matchesTVC 东西。

如果 matches 是情节提要中的独立视图控制器,您可以使用如下代码:

let matchesTVC: Matches = self.storyboard?.instantiateViewControllerWithIdentifier("Matches") as! Matches 
let navContr = UINavigationController(rootViewController:matchesTVC)
self.presentViewController(navContr, animated: true, completion: nil)