更改首先打开的视图(Xcode)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7512107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:00:23  来源:igfitidea点击:

Change which view opens first (Xcode)

iosxcodeview

提问by iOS developer

Possible Duplicate:
How to change the default 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?

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

回答by MillerMedia

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:

这是在您的 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;
}

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:

您所要做的就是更改 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;
}