0

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.

Community
  • 1
  • 1
Matte.Car
  • 2,007
  • 4
  • 23
  • 41

2 Answers2

1

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;
}
Joel
  • 15,654
  • 5
  • 37
  • 60
  • typing self.viewControllerFirst instead TutorialController * viewControllerFirst it returns this error: Property 'viewControllerFirst' not found on object of type 'AppDelegate *' – Matte.Car Oct 20 '13 at 21:36
  • You seem to be declaring the variable above. If you are not keeping a reference as a property of AppDelegate, then just declare the variable locally when you initialize. I've updated code above. – Joel Oct 20 '13 at 21:40
  • In both cases it appear a black screen with white bottom bar (an empty tabBar...). I modified code in question adding #import which I didn't wrote before, is it right? – Matte.Car Oct 20 '13 at 21:45
  • Edited answer. Try that. – Joel Oct 20 '13 at 21:54
  • Sorry but probably I'm doing a very big mistake, could you tell me where I'm wrong? Sorry but I'm going crazy!! Thank you so much!! https://copy.com/lZ6LRKBhbuQn4rzN – Matte.Car Oct 21 '13 at 21:03
  • You didn't mention you were using storyboards in your question. See here for the solution: http://stackoverflow.com/questions/8451975/conditionally-start-at-different-places-in-storyboard-from-appdelegate – Joel Oct 22 '13 at 00:27
  • Thank you, I didn't thought to tell that I'm using Storyboard. I'm looking that page but, actually, I haven't found a valid solution yet... – Matte.Car Oct 22 '13 at 16:59
0

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;
Joel
  • 15,654
  • 5
  • 37
  • 60
David Wong
  • 10,284
  • 3
  • 39
  • 34