I am working on application where after registration process home screen will appear. And the SWRevealViewController has been configure in home screen.
I want to configure SWRevealViewController programmatically.
Below is my code
let storyboard = UIStoryboard(name: "MainSW", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
let rvc:SWRevealViewController = self.revealViewController() as SWRevealViewController
rvc.pushFrontViewController(vc, animated: true)
But it gives me error like below.
Could not cast value of type 'UINavigationController' (0x110d9f860) to 'SWRevealViewController' (0x10dc346b8).
I have tried below link also
SWRevealViewController solution
But it also doesn't help me.
Here is how I have configured it :
I have created 2
UIBarButtonItemas properties of theHomeViewController(I will set them in code)In viewDidLoad method:
In viewWillAppear method:
This is all the code I use to set up SWRevealViewController in my HomeViewController in order to have left and right menu.
You can now use the delegate method to customize the behavior as it pleases you :
I have set an alpha on the HomeViewController to make it darker when it's not in front.
For the Storyboard part :
rearandrightsegues)front segue.root relationship)Keep in mind that you may also want to create a custom segue for the transition between your RegisterViewController and the HomeViewController.
You can create it programmatically too:
And in the
Storyboardchange the class segue from yourRegisterViewControllerto theSWRevealViewControllerto this new oneRegisterToHomeSegueand give it an identifier. So that in theRegisterViewControlleryou can call :And
voilà, you now have :Tell me if it is helping you.