Question

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.

Was it helpful?

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;
}

OTHER TIPS

You're not instanciating viewControllerStandard. You'll need something like this unless its been built in Interface Builder.

self.viewControllerStandard = [[TabBarController alloc] init];
self.viewControllerFirst = [[TutorialController alloc] init];
[self.viewController setViewControllers:@[self.viewControllerFirst] animated:NO];
window.rootViewController = self.viewControllerStandard;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top