0

Possible Duplicate:
applications expected to have a root view controller console

I'm trying to build the first app by following a book step by step but I guess I'm making a mistake. it's a simple view app with just a logo nd a label and then I click build and run and it says "build succeded", but when ios simulator pop up the app is still blank, even if I go back home and ropen the app nothing change. I see on the debug window this statement:

2012-10-26 04:07:03.376 welcome[1219:c07] Application windows are expected to have a root view controller at the end of application launch

AS far as I understand my app lacks of a root view controller but how can I implement it?

Community
  • 1
  • 1
Andrea
  • 125
  • 1
  • 7
  • That means you haven't set your app `rootViewController` ... Show your `didFinishLaunchingWithOptions:` method body ....It should look like @NSPostWhenIdle example - – TheTiger Oct 26 '12 at 13:57
  • in fact I can't see my view controller on my didfinishlaunchinfwithoptions: BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; – Andrea Oct 26 '12 at 14:16

1 Answers1

1

You specify the root view controller in your appDelegate class. It should look something like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.viewController = [[[ViewController alloc] initWithNibName:@"theNameOfMyXib" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

The important lines that you need to add are:

self.viewController = [[[ViewController alloc] initWithNibName:@"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;

And under initWithNibName you put the name of the xib you created your interface in.

Note: Only add autorelease if your project isn't using ARC.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • Thankyou, my root view controller is this. It's a little bit different from yours. #import "AppDelegate.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } – Andrea Oct 26 '12 at 14:12
  • I edited my appdelegate adding the lines you recommended but it displays some errors. here i have the screenshot of those errors: http://imageshack.us/photo/my-images/716/errorviewcontroller.png/ What ARC is? sorry for troubling you. – Andrea Oct 26 '12 at 14:29
  • sorry for the low quality img. You can't read the errors. here I uploaded a better quality one: – Andrea Oct 26 '12 at 14:33
  • Thx. I replaced those 2 file of your with mine but it gives me one error about cannot find the ViewController.h (in fact I don't have it) btw as soon as dropbox is no londer down I'll update the project so maybe you can see the problem. – Andrea Oct 26 '12 at 15:43