Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present View Controller modally on app launch?

I've created a screen that ONLY appears the first time that my app is launched; it works great. However, I'd like to present this screen modally on top of my root view controller (EditorsNoteViewController being the screen I want to present modally on first launch). Does anyone know how I would do this? Here is what I have so far:

Appdelegate.m

        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        {
            self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
            if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
            {
                NSLog(@"not first launch");

                      self.viewController = [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"articlesNav"];
                self.window.rootViewController = self.viewController;

            }
            else
            {
                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
                [[NSUserDefaults standardUserDefaults] synchronize];



                self.viewController = [[UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:@"articlesNav"];
                self.window.rootViewController = self.viewController;


     EditorsNoteViewController *vc = [[EditorsNoteViewController alloc]init];
             [self.viewController.navigationController presentViewController:vc animated:YES completion:nil];

}
                [self.window makeKeyAndVisible];
    return YES;
}
like image 335
Brittany Avatar asked Sep 08 '14 00:09

Brittany


1 Answers

I figured out that you'll have to call

[self.window makeKeyAndVisible];

before presenting the view controller

like image 164
dulgan Avatar answered Sep 22 '22 20:09

dulgan