Search code examples
iosobjective-cappdelegaterootview

Trouble setting FIrst view controller which will appear on App Startup using Storyboard


I'm setting setting FIrst view controller which will appear on my App Startup. It should appear an UIView first time as a tutorial and, from second time, another standard view. In AppDelegate I wrote this:

#import "AppDelegate.h"
#import "TabBarController.h"
#import "TutorialController.h"

@implementation AppDelegate

@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"Startup"]]) {

        TabBarController * viewControllerStandard = [[TabBarController alloc] init];
        window.rootViewController = viewControllerStandard;

    } else {

        TutorialController * viewControllerFirst = [[TutorialController alloc] init];
        window.rootViewController = viewControllerFirst;
        }

    [window makeKeyAndVisible];

    return YES;
}

It doesn't return any alert but, launching app, after splashscreen, it appear only a black screen. Without that codes everything works fine. What could be wrong? Thank you!

EDIT: I'm using Storyboard!

SOLVED: Solved using followben's reply.


Solution

  • You need to initialize the view controllers. For example

    #import "AppDelegate.h"
    #import "TabBarController.h"
    #import "TutorialController.h"
    
    @implementation AppDelegate
    
    @synthesize window;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        if ([@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"Startup"]]) {
    
            TabBarController *viewControllerStandard = [[TabBarController alloc] init];
            window.rootViewController = viewControllerStandard;
            [viewControllerStandard release]; //for non-arc
    
        } else { 
    
            TutorialController * viewControllerFirst = [[TutorialController alloc] init];
            window.rootViewController = viewControllerFirst; 
            [viewControllerFirst release]; //for non-arc
    
        }
    
        [window makeKeyAndVisible];
    
        return YES;
    }