Stack Overlow上有一些关于此错误的问题,但没有一个解决方案对我有用。有人能够浏览我的代码,看看为什么我收到以下错误?
应用程序在应用程序启动结束时应该有一个根视图控制器
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
答案 0 :(得分:1)
您将rootViewController
设置为self.viewController
,但您从未设置self.viewController
。
试试这个:
self.viewController = [sb instantiateViewControllerWithIdentifier:@"viewController"];
self.window.rootViewController = self.viewController;