微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SWRevealViewController使用swift以编程方式从菜单中打开第二个视图控制器

如何解决SWRevealViewController使用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)

解决方法

您可以使用frontViewController的{​​{1}}属性访问主屏幕控制器,如下所示:

SWRevealViewController

您可以使用let navigationController = revealViewController().frontViewController as? UINavigationController navigationController?.pushViewController(viewController,animated: false) 的{​​{1}}函数来替换frontViewController,例如:

setFront(_:animated:)
,

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

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)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。