如何设置根视图控制器
我设置了一个只有app委托类的空app,然后创建了一个xib来创建一个xib来布局应用程序并建立连接。
但是当我试图在iOS模拟器上运行应用程序时,我收到的错误如下:CoinToss [6212:f803]应用程序在应用程序启动结束时应该有一个根视图控制器终止以响应SpringBoard的终止。 程序以退出代码结束:0
为了为应用程序创建根视图控制器,我需要做什么?
谢谢。
在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; }
由于您显然正在使用.xib文件,因此请加载视图控制器并将窗口的rootViewController
属性设置为-application:didFinishLaunchingWithOptions:
的视图控制器-application:didFinishLaunchingWithOptions:
.
你需要设置两件事……
-
在AppDelegate.m文件中:
_applicationDidFinishLaunchingWithOptions_
self.window.rootViewController = self.viewController;
-
在application.m中
retVal = UIApplicationMain(argc,argv,nil,@“AppDelegate”);
应用程序应具有根视图控制器
在AppDelegate中替换
[window addSubview:[someController view]];
至
[self.window setRootViewController:someController];