简体   繁体   中英

Determine which UIViewController runs first

I started to learn objective-c and ios programming.I have two View Controller which are named MainViewController and GameViewController,also there are two xib files in my project.I connected xib files with the ViewController's.Totally Here are my files:

View Controllers,

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

and xibs,

    Main.xib
    Game.xib

I choose Main.xib as main interface in the project options.I'm trying to understand questions below,when i run this application first main.m runs.Thats okay.

After that does the AppDelegate class runs?How xcode determines which View Controller will run first?

With this project when i run,there is only black screen.Can anyone help me about an ios application's run order?

Xcode doesn't determine anything, it's entirely up to you to set up your UI after

-application:didFinishLaunchingWithOptions:launchOptions 

is called by the system. Below is an example where ExampleViewController is initialized first:

- (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;
}

The Application initialization flow is:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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