ios - 以编程方式打开连接到导航 Controller 的 View Controller

标签 ios swift xcode akswiftslidemenu

interfa builder flow我使用 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/

相关文章:

ios - 容器 View 将无法正确加载 View

swift - 更改堆栈 View 中多个字段之一的高度

ios - swift 和 iOS 7.1 的远程通知错误

ios - 如何防止大标题折叠

ios - 在 Swift 中将变量传递回父级

ios - Cocoa Touch Frameworks - 位码支持

ios - 如何使两次不同的碰撞产生不同的结果?

ios - 如何在 Xcode 8 中使用 Swift 3 创建 managedObjectContext?

ios - 支持 IPv6-only 网络应该注意什么?

ios - Swift:UITableView - 滑动以删除 - 如何在滑动时让单元格内容不移动