Black screen after App Startup

Matte.Car picture Matte.Car · Oct 21, 2013 · Viewed 7.4k times · Source

I'm setting First viewController which will appear on App Startup. That's my AppDelegate.h:

#import "AppDelegate.h"
#import "TutorialController.h" // a simple UIViewController

@implementation AppDelegate

@synthesize window;

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

    window.rootViewController = [[TutorialController alloc] init];

    [window makeKeyAndVisible];

    return YES;
}

It doesn't give any alert but, launching app, after splashscreen, it appear only a black screen. Without that code everything works fine. I can't do that in StoryBoard because, after solving this trouble, I've got to add other things... What could be wrong? Thank you!

SOLVED: Solved using followben's reply.

Answer

incmiko picture incmiko · Oct 21, 2013

.h:

@class MainViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong,nonatomic) MainViewController *mainViewController;

.m:

#import "MainViewController.h"

@implementation AppDelegate
@synthesize mainViewController;


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


    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    self.window.rootViewController = self.mainViewController;
    [self.window makeKeyAndVisible];
    return YES;
}

EDIT, with the complete project link (zipped) ( working :) )

EDIT2:

if you are working with Storyboard, make a storyboard file, and assign it with the project's storyboard like you see on this picture: Main interface is the same as your storyboard file name.

enter image description here and you don't have to write anything into your app delegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    return YES;
}

You can set the starting page by moving this little arrow to a ViewController which you want to set the starter like on this pic:

enter image description here

if you want to assign your ViewController ( in storyboard ) with your new TutorialViewController make it like this:

enter image description here