【问题标题】:Change which view opens first (Xcode) [duplicate]更改首先打开的视图(Xcode)[重复]
【发布时间】:2011-09-22 08:53:07
【问题描述】:

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

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

【问题讨论】:

    标签: ios xcode view


    【解决方案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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-28
      • 1970-01-01
      • 2014-12-09
      • 2013-06-28
      相关资源
      最近更新 更多