更改哪个视图首先打开(Xcode)

时间:2011-09-22 08:53:07

标签: ios xcode view

  

可能重复:
  How to change the default View Controller that is loaded when app launches?

因此,如果我创建了一个应用程序并且默认情况下首先打开某个视图,并且决定我要更改哪个视图首先打开,我该怎么做?

1 个答案:

答案 0 :(得分:1)

这是在AppDelegate.m文件中的方法(或应用程序委托文件的标题)中控制的,名为didFinishLaunchingWithOptions。例如,在我创建的标签栏应用程序中,它看起来像这样:

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

您所要做的就是更改self.window.rootViewController的值。例如,假设您希望MapViewController成为第一个打开的页面。你可以这样做:

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