user4238267
user4238267

Reputation:

SWRevealViewController not able to call from the appdelegate.m

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

Upvotes: 0

Views: 957

Answers (6)

webjunkie
webjunkie

Reputation: 1184

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)

Upvotes: 3

abdul sathar
abdul sathar

Reputation: 2396

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;

Upvotes: 1

Tj3n
Tj3n

Reputation: 9943

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;
    }

Upvotes: 0

Gerry
Gerry

Reputation: 13

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

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

SWRevealViewController *viewController = revealController;

Upvotes: 0

Asd Asdf
Asd Asdf

Reputation: 21

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 ... */
}

Upvotes: 0

Uma Madhavi
Uma Madhavi

Reputation: 4917

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

Upvotes: 0

Related Questions