繁体   English   中英

在Swift中从AppDelegate加载嵌入到UINavigationController的控制器

[英]Load a controller embed to a UINavigationController from AppDelegate in Swift

我需要从AppDelegate显示嵌入到UINavigationController的表视图。

通常我用

    let viewController: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("prova") as ViewController
    window?.rootViewController?.presentViewController(viewController, animated: false, completion: nil)

但是它不适用于嵌入式控制器,如何修改此代码?

这是一个测试项目。

您需要从情节UINavigationController实例化UINavigationController及其标识符。 导航控制器应连接到情节提要中的rootViewController并将自动显示。

let navController: UINavigationController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("provaNavController") as UINavigationController
window?.rootViewController?.presentViewController(navController, animated: false, completion: nil)

更新

由于您没有在情节提要中设置初始视图控制器,因此请使用以下代码:

window = UIWindow(frame: UIScreen.mainScreen().bounds)
let navController: UINavigationController = UIStoryboard(name: "Main", bundle:nil).instantiateViewControllerWithIdentifier("provaNavController") as UINavigationController
window?.rootViewController = navController
window?.makeKeyAndVisible()

您还需要从常规项目设置中清除Main.storyboard: 在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM