0

My app was launching fine earlier today and now I'm getting this error

"Applications are expected to have a root view controller at the end of application launch"

I've looked at other threads saying to change my code, but I never changed any code to get to this point.

Delegate.h

@interface halo4AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>{
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

Delegate.m

@implementation halo4AppDelegate

@synthesize window;
@synthesize tabBarController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{   
    sleep(3);
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}


#pragma mark -
#pragma mark Memory management

- (void)dealloc {
    [tabBarController release];
    [window release];
    [super dealloc];
}

@end

The xib for my FirstViewController is titles FirstView.xib , ext

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1350228
  • 59
  • 1
  • 7
  • i saw a few problems in there. – Nicos Karalis Jul 11 '12 at 01:07
  • first, you never set the window size ``self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];``, second you never instantiate the controllers that will be on your tabbar ``UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];`` and ``UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];``, third you don't initiate the tab bar with ``self.tabBarController = [[UITabBarController alloc] init];`` – Nicos Karalis Jul 11 '12 at 01:09
  • and finally just add the controllers to your tabbar ``[self.tabBarController setViewControllers:[NSArray arrayWithObjects:viewController1, viewController2, nil]];`` – Nicos Karalis Jul 11 '12 at 01:10
  • after all that you add your previous code ``sleep(3);`` ``self.window.rootViewController = self.tabBarController;`` ``[self.window makeKeyAndVisible];`` ``return YES;`` – Nicos Karalis Jul 11 '12 at 01:11
  • Im pretty new to this, would you mind telling my where this code needs to go or perhaps place it in the code for me. BTW is there a way i can give u reputation or anything like that? thanks for all this help – user1350228 Jul 11 '12 at 01:13
  • just vote up if the answer helps and choose the answer if it helps, by the way if you need more help contact me by email on my profile, this is not a good place to make a discussion – Nicos Karalis Jul 11 '12 at 01:18

1 Answers1

1

This is not an error, more like a warning.

In your application delegate there is a method named application:didFinishLaunchingWithOptions: in this method you have to make this line before the end of the method self.window.rootViewController = [Some UIViewController]

again, this is not an error, you can ignore the rootViewController IF you have another way to create this rootViewController.

EDIT

This is what your method should looks like:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
  UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
  UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
  self.tabBarController = [[UITabBarController alloc] init];
  self.tabBarController.viewControllers = @[viewController1, viewController2];
  self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}
Nicos Karalis
  • 3,724
  • 4
  • 33
  • 62
  • 1
    My issue is that when i run the app in iOS simulator the launch screen is displayed followed by a black screen and nothing happens – user1350228 Jul 11 '12 at 00:37
  • can you post the ``application:didFinishLaunchingWithOptions:`` ? – Nicos Karalis Jul 11 '12 at 00:37
  • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions – user1350228 Jul 11 '12 at 00:44
  • Im getting various errors, sorry for bothering you. Why are these changes necessary. Everything was working perfectly a few hours ago – user1350228 Jul 11 '12 at 00:56
  • can you give more details about your code? like post it on github or make a gist about the important classes. to help you i need more information, like the controller you want to start with, etc... – Nicos Karalis Jul 11 '12 at 00:58
  • What is that "@" sign in `self.tabBarController.viewControllers = @[viewController1, viewController2];`? Is it a new way to instantiate an array? – Stas Aug 14 '12 at 05:54
  • Sorry... Yes... This is how you can create an NSArray: `@[objects...]` if you want to use the old way: `[NSArray arrayWithObjects:objects, ..., nil]` – Nicos Karalis Aug 14 '12 at 09:57