我正在尝试从我的 AppDelegate 打开 Storyboard,但它抛出了异常:
2016-10-25 10:26:16.776 momnt[22865:1300106] *** Terminating app due to
uncaught exception 'NSInternalInconsistencyException',
reason: 'Application windows are expected to have a root view
controller at the end of application launch'
这是我正在尝试做的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *loginStoryboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
UIViewController *mainViewController = [loginStoryboard instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];
return YES;
}
我读到较新版本的 XCode 要求所有 Windows 都必须有一个 rootViewController,但我已经做到了。
最佳答案
调试应用程序并检查 mainViewController
是否不是 nil
。
问题似乎是您没有在 Storyboard中将任何 viewController 设置为初始 viewcontroller。
将您想要的任何 View Controller 设置为初始 View Controller ,您的代码可以正常工作。
或者
使用instantiateViewControllerWithIdentifier
并将您想要作为初始viewController的viewController标识符传递给它。
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
UIViewController *mainViewController = [storybord instantiateViewControllerWithIdentifier:@"InitialViewControllerID"];
self.window.rootViewController = mainViewController;
[self.window makeKeyAndVisible];
关于ios - AppDelegate 抛出 NSInternalInconsistencyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40240122/