Rwehner186 Rwehner186 - 4 months ago 33x
iOS Question

Show Tutorial View on First App Opening Only

I'm trying to create an introduction/welcome screen that displays only during the first opening of an app. I've had some success with the help of user 'chroipahtz' here, but can only get a black view to appear instead of my welcome ViewController. Note: This black screen does dismiss to the rest of my app correctly, and the app runs without errors or warnings.

screen shot of black screen

I have the following code in the root view controller "viewDidLoad" method:

if(![[NSUserDefaults standardUserDefaults] boolForKey:@"hasSeenTutorial"])
WelcomeViewController *welcomeController = [[WelcomeViewController alloc] init];
[self.navigationController pushViewController:welcomeController animated:YES];
else{ NSLog(@"Tutorial has been seen");}
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"hasSeenTutorial"];

which displays the introduction view on the first opening. I have created a View Controller in storyboard, and have assigned it the correct custom class in the identity inspector.

screen shot of storyboard

I have included the header:

#import "WelcomeViewController.h"

Please provide guidance if you can as to why the Welcome View Controller interface isn't displaying the grey view with text I've outlined in storyboard.


You need to push another view in the event of "else". The below code is a bit more robust and makes use of storyboard. You must name the view controllers and the storyboard for this to work:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

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

    if(![[NSUserDefaults standardUserDefaults] dictionaryForKey:@"hasSeenTutorial"]){
        UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"welcomeViewController"];
        self.window.rootViewController = viewController;
    } else {
        UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"nonWelcomeViewController"];
        self.window.rootViewController = viewController;

    [self.window makeKeyAndVisible];

    // Override point for customization after application launch.

    return YES;