开发者

Change which view opens first (Xcode) [duplicate]

开发者 https://www.devze.com 2023-04-06 20:36 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: How to change the defaul开发者_StackOverflow中文版t View Controller that is loaded when app launches?
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

How to change the defaul开发者_StackOverflow中文版t View Controller that is loaded when app launches?

So if I made an app and a certain view opens first by default, and decide I want to change which view opens first, how would I do that?


That is controlled in the method in your AppDelegate.m file (or whatever the title of your app delegate file is) called didFinishLaunchingWithOptions. For example, in a tab bar app I've created it looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // Add the tab bar controller's current view as a subview of the window

    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

All you have to do is change the value of the self.window.rootViewController. For example, let's say you want a MapViewController to become the first page to open. You could do something like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    // Add the tab bar controller's current view as a subview of the window
    MapViewController *mvc = [[MapViewController alloc]initWithNibName:@"MapViewController" bundle:nil]; //Allocate the View Controller

    self.window.rootViewController = mvc;   //Set the view controller
    [self.window makeKeyAndVisible];  
    [mvc release];    //Release the memory
    return YES;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消