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;
}
精彩评论