我使用 AKSwiftSlideMenu 作为应用程序的基础。
我有一个连接到导航 Controller 的 View Controller (HomeVC)。
如果 Storyboard入口点指向 HomeVC,那么我当然会得到菜单,但我的应用程序需要在没有菜单的情况下启动,并且只有在完成某些屏幕和任务之后,我想导航到 HomeVC 并允许用户访问菜单。
我注意到,如果我在没有连接到导航 Controller 的启动 View Controller 上放置一个按钮,并通过拖动+cntrl将该按钮直接连接到导航 Controller ,那么按下该按钮将使我进入 View 没有菜单的 Controller 到 HomeVC 并显示菜单。
我如何以编程方式做到这一点
预先感谢您的帮助
编辑:我尝试过以下代码
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "Home") as! UINavigationController
self.present(newViewController, animated: true, completion: nil)
这不起作用,导致出现以下错误
无法将类型“myApp.HomeVC”(0x10a159280) 的值转换为“UINavigationController”(0x10cc2d3c8)。
最佳答案
let newViewController = storyBoard.instantiateViewController(withIdentifier: "Home") as! UINavigationController
s
“Home”不是 UINavigationController。删除为! UINavigationController
从这一行开始,错误就会消失。
关于ios - 以编程方式打开连接到导航 Controller 的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43963112/