以编程方式呈现ViewController的嵌入NavigationController

时间:2017-07-17 07:07:27

标签: ios swift uinavigationcontroller

所以我有一个嵌入导航控制器的PageViewController登录界面。根据我的理解,我必须提供根导航控制器,以便为我的PageViewController导航栏。

因此,以编程方式显示PageViewController将无效。

通过将PageVC设置为NavVC的根视图控制器,我已将PageVC嵌入NavVC

最优雅的方式是什么?我需要能够在应用中的多个位置显示PageViewController(嵌入在NavigationController中)。

2 个答案:

答案 0 :(得分:1)

sbt new sbt/scala-seed.g8 声明类方法

PageVC

现在你要出席的地方

class func viewController () -> PageVC {
    return UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Your Identifier") as! PageVC
}

您可以在任何需要的地方使用此代码

答案 1 :(得分:0)

可能提供更多代码示例?我无法分辨你的情况。

一个建议就是简单地从您拥有的管理控制器中提供包含PageViewController的navController,无论是初始视图的UIViewController还是您的UITabBarController有。无论如何,您必须提供或设置UINavigationController作为根。