I am new to Swift and I am trying to implement side navigation using SWrevealcontroller
I have a root VC which has a button when click on this button I am navigating to UITabBarController
Here is how my storyboard looks like (below)
and this is how I am navigating on button click
@IBAction func clickButton(_ sender: Any) {
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "Home") as! UITabBarController
self.present(nextViewController, animated:true, completion:nil)
}
This is my code in FirstViewController
override func viewDidLoad() {
super.viewDidLoad()
barButton.target = self.revealViewController()
barButton.action = #selector(SWRevealViewController.revealToggle(_:))
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
But I am getting error at line when I navigate from root VC to UITabBarController
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
Fatal error: Unexpectedly found nil while unwrapping an Optional value
Can someone help me what is wrong here.
TIA
You need to present your RevealViewController
instead of the UITabBarController
.
Add a Storyboard ID
to your RevealViewController
:
And then present it in your clickButton(_:)
function, like this:
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "RevealViewControllerID")
self.present(nextViewController, animated: true)