繁体   English   中英

SWRevealViewController 使用 swift 从菜单以编程方式打开第二个视图 controller

[英]SWRevealViewController Open second view controller from menu programatically using swift

我在我的应用程序中使用 SWRevealViewController。 一切都很好,除了一件事。

假设我的 SWRevealViewController 菜单中有 A、B、C 3 个项目。 我想使用 swift 以编程方式打开 B 项。

更新:代码

 let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let sw = storyboard.instantiateViewController(withIdentifier: "Reveal") as! SWRevealViewController
        let destinationController = storyboard.instantiateViewController(withIdentifier: "VehicleList") as! VehicleList
        let navigationController = UINavigationController(rootViewController: destinationController)
        sw.pushFrontViewController(navigationController, animated: true)

您可以使用 SWRevealViewController 的frontViewController属性访问主屏幕SWRevealViewController ,如下所示:

let navigationController = revealViewController().frontViewController as? UINavigationController
navigationController?.pushViewController(viewController, animated: false)

您可以使用 SWRevealViewController 的setFront(_:animated:) function 替换SWRevealViewController ,例如:

revealViewController()?.setFront(viewController, animated: false)

这是我的问题的完整解决方案之二。

let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let destinationController = storyboard.instantiateViewController(withIdentifier: "VehicleList") as! VehicleList
        let navigationController = revealViewController().frontViewController as? UINavigationController
        navigationController?.pushViewController(destinationController, animated: false)

暂无
暂无

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

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