【问题标题】:SWRevealViewController Open second view controller from menu programatically using swiftSWRevealViewController 使用 swift 以编程方式从菜单中打开第二个视图控制器
【发布时间】:2020-12-05 15:30:14
【问题描述】:

我在我的应用程序中使用 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)

【问题讨论】:

  • 请添加您尝试过的代码
  • @SylvanDAsh 我在我的问题中添加了代码。

标签: ios swift xcode swrevealviewcontroller


【解决方案1】:

您可以像这样使用SWRevealViewControllerfrontViewController 属性访问主屏幕控制器:

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

您可以使用SWRevealViewControllersetFront(_:animated:) 函数替换frontViewController,例如:

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

【讨论】:

  • 感谢您的帮助。你的前 2 行确实对我有用,但有一些补充。我完整回答。谢谢@gcharita
【解决方案2】:

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

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)

【讨论】:

  • 无需在第 2 行的 Storyboard 中实例化 SWRevealViewController
  • 你是对的。这段代码是上次更新留下的。让我更新一下。
猜你喜欢
  • 1970-01-01
  • 2015-09-10
  • 2016-08-19
  • 2016-06-20
  • 2015-09-07
  • 1970-01-01
  • 2019-03-16
  • 2017-01-22
  • 1970-01-01
相关资源
最近更新 更多