SWRevealViewController - push view controller from side menu

5.4k views Asked by At

I've set up my app using the SWRevealViewController and it's working fine but I want to change how it works. At the moment I have the following views on the same level:

  • Home
  • View A
  • View B

But I want:

  • Home
    • View A
    • View B

I still want Home, View A, View B to be in the menu but when clicking on View A or View B it gets pushed onto Home. And in the navigation bar it has a back button instead of the menu button.

Is this possible using SWRevealViewController?

2

There are 2 answers

0
Anbu.Karthik On

in objective-C

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
SWRevealViewController *main = (SWRevealViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SWRevealViewController"];
[self presentViewController:main animated:YES completion:nil];

in swift -- it automatically open the your root view controller of SWL

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let main = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! UIViewController //SWRevealViewController
self.presentViewController(main, animated: true, completion: nil)
0
Shivansh Jagga On

I found an answer and hopefully it helps someone reading this. It has both ways, SideMenu when you have a tabBarController or only a NavigationController. Posting snippet from answer, which worked for me.

With TabBar Controller:

UITabBarController *tbc = (UITabBarController *)self.revealViewController.frontViewController;
    UINavigationController *nc = tbc.selectedViewController;
    [nc pushViewController:myVC animated:NO];
    [self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];

With Navigation Controller:

UINavigationController *frontVC = (UINavigationController *)self.revealViewController.frontViewController;
[frontVC pushViewController: yourVC animated:NO];
[self.revealViewController pushFrontViewController:frontVC animated:YES];