Stack Overlow 上有一些关于此错误的问题,但似乎没有一个解决方案对我有用。有人能看一眼我的代码,看看我为什么会收到以下错误吗?
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
最佳答案
您将 rootViewController
设置为 self.viewController
但您从未设置 self.viewController
。
试试这个:
self.viewController = [sb instantiateViewControllerWithIdentifier:@"viewController"];
self.window.rootViewController = self.viewController;
关于ios - 关于在应用程序启动结束时有 Root View Controller 的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23532115/