如何设置根视图控制器 [英] How to set root view controller
问题描述
我设置了一个只有app委托类的空应用程序,然后子类化了一个视图控制器类来创建一个xib来布局应用程序并建立连接。
I set up an empty app with only an app delegate class, then subclassed a view controller class to create a xib to layout the app and make connections.
但是当我尝试在iOS模拟器上运行应用程序时,我收到的错误如下:CoinToss [6212:f803]应用程序应该有一个根视图控制器应用程序启动结束
终止以响应SpringBoard的终止。
程序以退出代码结束:0
But when I tried to run the app on iOS Simulator, I got an error which read: CoinToss[6212:f803] Applications are expected to have a root view controller at the end of application launch Terminating in response to SpringBoard's termination. Program ended with exit code: 0
为了为应用程序创建根视图控制器,我需要做什么?
What do I need to do in order to create a root view controller for the app?
谢谢。
推荐答案
在AppDelegate.m中
in AppDelegate.m
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIViewController *viewController = // determine the initial view controller here and instantiate it with [storyboard instantiateViewControllerWithIdentifier:];
self.window.rootViewController = viewController;//making a view to root view
[self.window makeKeyAndVisible];
return YES;
}
这篇关于如何设置根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!