0

I am calling SWRevealViewController in Appdelegate.m

SWRevealViewController *svc = self.revealViewController;
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    FrontVC *homeVC = [storyboard instantiateViewControllerWithIdentifier:@"FrontVC"];
    [svc setFrontViewController:homeVC animated:NO];
    [svc revealToggleAnimated:YES];

But i am not able to load FrontVC controlller . what is right way to call

  • Isnt it easier to follow the detailed tutorial in [Appcoda](http://www.appcoda.com/ios-programming-sidebar-navigation-menu/)? U can implements it in storyboard, just put the start pointer to the SWRevealViewController then u done – Tj3n Oct 15 '15 at 11:25

6 Answers6

3

For Swift 2.2

let storyboard = UIStoryboard(name: "Main", bundle: nil)

let sw = storyboard.instantiateViewControllerWithIdentifier("SWRevealViewController") as! SWRevealViewController

self.window?.rootViewController = sw

let cv = storyboard.instantiateViewControllerWithIdentifier("IDOFCONTROLLER") as! NAMEOFCONTROLLER

let navigationController = UINavigationController(rootViewController: cv)

sw.pushFrontViewController(navigationController, animated: true)
webjunkie
  • 1,184
  • 9
  • 19
1

I hope this one helps.

UIStoryboard * storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        // this any item in list you want navigate to
        yourHomeViewController *home = (yourHomeViewController *) [storyboard instantiateViewControllerWithIdentifier:@"leid"];

        yourSideMenuViewController *slidemenu = (yourSideMenuViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MenuView"];

        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:home];

        UINavigationController *smVC = [[UINavigationController alloc]initWithRootViewController:slidemenu];

        // define rear and frontviewcontroller
        SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:smVC frontViewController:nav];

        // make it as root
        self.window.rootViewController = revealController;
abdul sathar
  • 2,395
  • 2
  • 28
  • 38
  • This works perfect for me, the only problem is that - It hides a back button for me as Im navigating to a child view controller. – Sipho Koza Sep 06 '16 at 11:22
  • yes I managed to make it work for me. But you need to have a start indicator in the SWRevealViewController in your storyboard, then put the above code on app delegate – Sipho Koza Sep 26 '16 at 13:05
0

We can't call RevealViewController in App Delegate. You can directly add this in Your ViewController for Front & rear.

Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73
  • there i have added .all is working after loged in user .i want avoid the user to go login screen so from didFinishLaunchingWithOptions method i want to call SWRevealViewController . to go home screen. –  Oct 15 '15 at 11:24
  • Give the user a BOOL value in NSUserDefault that indicator if the user have not logged out yet, put it in Appdelegate then check when app start and go straight to your needed ViewController – Tj3n Oct 15 '15 at 11:27
0

Have you declared and initialized revealViewController anything like this?

@interface AppDelegate ()
    @property (strong, nonatomic) SWRevealViewController *revealViewController;
@end

/* ... */

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.revealViewController = /* ... init ... */;
    /* ... your code here ... */
}
Asd Asdf
  • 21
  • 6
0

I didn't use a storyboard but did it like this:

SWRevealViewController *revealController = [[SWRevealViewController    alloc] initWithRearViewController:menuViewController frontViewController:frontNavigationController];

SWRevealViewController *viewController = revealController;
Gerry
  • 13
  • 4
0

I think u can put the start indicator in the SWRevealViewController in ur storyboard, give the login VC a name

//if user is logged in - In login VC 
[[NSUserDefaults standardUserDefaults] setValue:1 forKey:isLogged];

//In Appdelegate
if([[NSUserDefaults standardUserDefaults] valueForKey:isLogged] == 1)
    {
        NSLog(@"have data");
//Start straight into normal SWRevealVC
        self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController]; 
    }
    else
    {

//If not, make your root VC the login viewcontroller
        UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"LoginViewController"];

        self.window.rootViewController = rootController;
    }
Tj3n
  • 9,837
  • 2
  • 24
  • 35