确定首先运行哪个UIViewController

时间:2012-12-22 22:14:53

标签: objective-c ios delegates viewcontroller

我开始学习objective-c和ios编程。我有两个名为MainViewController和GameViewController的View Controller,我的项目中还有两个xib文件。我用ViewController连接了xib文件。总结这里是我的文件:

查看控制器,

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

和xibs,

    Main.xib
    Game.xib

我选择Main.xib作为项目选项中的主界面。我正在尝试理解下面的问题,当我运行此应用程序时,首先运行main.m.Thats没关系。

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

当我运行这个项目时,只有黑屏。任何人都可以帮我解决ios应用程序的运行顺序吗?

1 个答案:

答案 0 :(得分:3)

Xcode没有确定任何内容,完全取决于你在

之后设置你的用户界面
-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