繁体   English   中英

确定哪个UIViewController首先运行

[英]Determine which UIViewController runs first

我开始学习Objective-C和ios编程。我有两个名为MainViewController和GameViewController的View Controller,在我的项目中还有两个xib文件。我将xib文件与ViewController的文件连接在一起。以下是我的文件:

查看控制器,

    AppDelegate.h
    AppDelegate.m
    MainViewController.h
    MainViewController.m
    GameViewController.h
    GameViewController.m

和小臂

    Main.xib
    Game.xib

我在项目选项中选择Main.xib作为主界面。当我第一次运行main.m运行该应用程序时,我试图理解以下问题。

之后,AppDelegate类将运行?xcode如何确定哪个View Controller首先运行?

当我运行该项目时,只有黑屏。有人可以帮助我了解ios应用程序的运行顺序吗?

Xcode不会决定任何事情,这完全取决于您在之后设置UI

-application:didFinishLaunchingWithOptions:launchOptions 

由系统调用。 下面是一个示例,其中ExampleViewController被初始化:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ExampleViewController alloc] initWithNibName:@"ExampleViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

应用程序初始化流程为:

main() -> AppDelegate (or whatever class has been designated the delegate) -> initial view controller

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM