swift - 如何在导航 Controller SWIFT 中呈现 View Controller

标签 swift uiviewcontroller uinavigationcontroller

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

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

}

如何显示它内部的导航 Controller ?

最佳答案

Storyboard中是否有导航 Controller ?如果是这样,给它一个 Storyboard ID 并将你的 matchesTVC 内容替换为导航 Controller 。

如果 matches 是 Storyboard中的独立 View Controller ,您可以使用如下代码来实现:

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

关于swift - 如何在导航 Controller SWIFT 中呈现 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29974858/

相关文章:

uinavigationcontroller - 使用 Xcode 4.3.2 创建 UINavigationController iOS 应用程序而不使用 Storyboard

iphone - 隐藏模态选项卡栏 Controller - 从 View Controller 内的选项卡栏 Controller 中

ios - 获取应用内购买自动续订订阅结束日期的最佳策略

swift - 是否可以在初始化时直接改变属性/变量?

swift - nsMutableUrl addvalue 在 key 周围添加引号 ""

objective-c - UIViewController 子类无法分配实例变量

objective-c - 尝试在其 View 不在窗口层次结构中的 UIViewController 上呈现 UIAlertController

ios - Swift AVPlayer seekToTime 问题

iphone - 为什么 Interface Builder 不会更改我的 ViewController 类型?

swift - 在 Swift 中,导航栏消失并且永远不会回来