我的目标是以编程方式实例化SWRevealController,但似乎,但每次都会崩溃
这是代码
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "OnJobViewControllerID") as? OnJobViewController {
var firstName = "Aegon"
vc.driverName.text = firstName
let navController = UINavigationController(rootViewController: vc)
navController.setViewControllers([vc], animated:true)
self.revealViewController().setFront(navController, animated: true)
}
OnJobViewController是ViewController
总是在这里崩溃。
为清楚起见,这是我的故事板
主视图控制器
SetFront segue
SetRear segue
答案 0 :(得分:0)
试试这个: -
let frontNavigationController:UINavigationController
let rearNavigationController:UINavigationController
let revealController = SWRevealViewController()
var mainRevealController = SWRevealViewController()
let objStoryboardMain = UIStoryboard(name: "Main",
bundle: nil)
let sidebar = objStoryboardMain.instantiateViewController(withIdentifier: "viewSideMenu")as! SideMenuViewController
let homepage = objStoryboardMain.instantiateViewController(withIdentifier: "viewHomePage") as! HomePageViewController
frontNavigationController = UINavigationController(rootViewController: homepage)
rearNavigationController = UINavigationController(rootViewController: sidebar)
revealController.frontViewController = frontNavigationController
revealController.rearViewController = rearNavigationController
revealController.delegate = self
mainRevealController = revealController
self.window?.rootViewController = mainRevealController
self.window?.makeKeyAndVisible()
<强>参考: - 强>
https://github.com/John-Lluch/SWRevealViewController
答案 1 :(得分:-1)
希望您在AppDelegate中配置SWRevealViewController。 这是我的实施,希望它能帮到你。 1 GT; import SWRevealViewController:
import SWRevealViewController
2 - ;实现委托:
class AppDelegate: UIResponder, UIApplicationDelegate, SWRevealViewControllerDelegate {
3&GT;从revealeController创建一个对象:
var swRevealController: SWRevealViewController!
4&GT;现在您可以使用我自己的要求实例化以下代码的SWRevealController。
func gotoPaymentVC(_ ride: Ride) {
let acceptedVC = storyboard.instantiateViewController(withIdentifier: "PaymentVC") as! PaymentVC
acceptedVC.ride = ride
let rearViewController = storyboard.instantiateViewController(withIdentifier: "LeftMenuVC") as! LeftMenuVC
mainNavController = UINavigationController(rootViewController: acceptedVC)
mainNavController.isNavigationBarHidden = true
let mainRevealController = SWRevealViewController(rearViewController: rearViewController, frontViewController: mainNavController)
mainRevealController?.delegate = self
self.swRevealController = mainRevealController
self.window!.rootViewController = self.swRevealController
self.window!.makeKeyAndVisible()
}