0

There are some questions on Stack Overlow regarding this error, but none of the solutions seemed to work for me. Would someone be able to glance at my code and see why I am getting the following error?

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

AppDelegate.m:

#import "AppDelegate.h"
#import "ViewController.h" //import header file

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:@"viewController"];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

@end
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    Update your question by pasting in (and formatting) the relevant code. – rmaddy May 08 '14 at 03:18
  • Wouldn't it be neater to just do what I did? – user3525783 May 08 '14 at 03:20
  • 1
    Questions on SO need to be self-contained so they remain useful in the future. Please include the _minimum_ code necessary to reproduce the problem, not a link, and not all your code. Also, given that this has been asked many times, please explain in more detail what you've tried and why the other solutions didn't work for you. – jscs May 08 '14 at 03:20
  • Please let me know if any of the other files are required for help in the debugging process. I tried the solutions from this question: http://stackoverflow.com/questions/7520971/applications-are-expected-to-have-a-root-view-controller-at-the-end-of-applicati?rq=1 – user3525783 May 08 '14 at 03:26

1 Answers1

1

You are setting the rootViewController to self.viewController but you never set self.viewController.

Try this:

self.viewController = [sb instantiateViewControllerWithIdentifier:@"viewController"];
self.window.rootViewController = self.viewController;
rmaddy
  • 314,917
  • 42
  • 532
  • 579