【发布时间】:2011-09-22 08:53:07
【问题描述】:
可能重复:
How to change the default View Controller that is loaded when app launches?
因此,如果我创建了一个应用,并且默认情况下首先打开某个视图,并决定要更改首先打开哪个视图,我该怎么做?
【问题讨论】:
可能重复:
How to change the default View Controller that is loaded when app launches?
因此,如果我创建了一个应用,并且默认情况下首先打开某个视图,并决定要更改首先打开哪个视图,我该怎么做?
【问题讨论】:
这在您的 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;
}
【讨论】: