문제

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