Search code examples
objective-cios7

Loginview Before TabBarController


Instantly present the LoginViewController in my appdelegate before my tabbarcontroller

i tried with this code block and also name the navagation controller Identity to "log"

 UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *logincontroller=[storyboard instantiateViewControllerWithIdentifier:@"log"];
[tabBarController presentViewController:logincontroller animated:YES completion:NULL];

Warning: Attempt to present on whose view is not in the window hierarchy!

Please any ideas.


Solution

  • You have to use self.window.rootViewController when you are in appDelegate:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    LoginViewController *logincontroller= [storyboard instantiateViewControllerWithIdentifier:@"log"];
    [self.window.rootViewController presentViewController:logincontroller animated:NO completion:nil];
    

    I dont think you see what I am trying to point out, You are using UINavigationController, but the UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. You are trying to present the login view modally so it is not part of the navigation stack.

    You should be looking for LoginViewController and create a new instance of it using its storyboard Id.