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
有帮助吗?

解决方案

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;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top