如何设置根视图控制器

pde*_*ger 15 xcode ios

我设置了一个只有app委托类的空应用程序,然后将视图控制器类子类化以创建一个xib来布局应用程序并建立连接.

但是当我尝试在iOS模拟器上运行应用程序时,我收到一条错误:CoinToss [6212:f803]应用程序在应用程序启动结束时应该有一个根视图控制器终止以响应SpringBoard的终止.程序以退出代码结束:0

为了为应用程序创建根视图控制器,我需要做什么?

谢谢.

小智 23

在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;
}
Run Code Online (Sandbox Code Playgroud)


Cal*_*leb 0

由于您显然正在使用 .xib 文件,因此加载视图控制器并将窗口的属性设置rootViewController为 .xib 文件中的视图控制器-application:didFinishLaunchingWithOptions: