How to call a Rootviewcontroller on iOS

2020-03-07 07:01发布

问题:

In my iOS application launch im checking wether user is registered user or new user(like facebook & skype), than if user is not register i'm navigating app to register screen with my App delegate:

    if (user != register){

        RegisterViewController *registerViewController = [[RegisterViewController alloc] init];
                RearViewController *rearViewController = [[RearViewController alloc] init];

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:registerViewController];

        self.viewController = revealController;

        self.window.rootViewController = self.viewController;

        self.window makeKeyAndVisible];
    }else {

FrontViewController *frontViewController = [[FrontViewController alloc] init];
            RearViewController *rearViewController = [[RearViewController alloc] init];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];

RevealController *revealController = [[RevealController alloc] initWithFrontViewController:navigationController rearViewController:rearViewController];

self.viewController = revealController;

self.window.rootViewController = self.viewController;

[self.window makeKeyAndVisible];

}

This way if user is not registereds I now have register screen as a main window,

My problem is : after user finish registration im im getting two Navigation controller on top of my screen

im using:

[[self navigationController] pushViewController:revealController animated:YES];

to navigate application to my main viewController since user is now registered,

how to fix this and is there any other way to fix register user issue

回答1:

As you need another root view controller, why not to set it instead of pushing to another navController stack:

[[UIApplication sharedApplication] keyWindow].rootViewController = revealController;