0
votes

I am using SWRevealViewController in my app. Everything is fine except one thing.

Suppose there are A,B,C 3 items in my SWRevealViewController Menu. I want to open B item programatically using swift.

UPDATE: CODE

 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)
2
Please add code of what you have tried - Sylvan D Ash
@SylvanDAsh I have added code in my question. - Mohammad Aamir

2 Answers

0
votes

You can have access to the main screen controller using frontViewController property of the SWRevealViewController like that:

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

You can replace the frontViewController using setFront(_:animated:) function of SWRevealViewController like:

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

This is complete solution two my question.

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)