Ios 更改首先打开的视图(Xcode)
可能重复:Ios 更改首先打开的视图(Xcode),ios,xcode,view,Ios,Xcode,View,可能重复: 因此,如果我制作了一个应用程序,并且某个视图在默认情况下首先打开,并且决定要更改首先打开的视图,我将如何执行此操作?该操作由AppDelegate.m文件(或应用程序委派文件的标题)中名为didFinishLaunchingWithOptions的方法控制。例如,在我创建的选项卡栏应用程序中,它如下所示: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDiction
因此,如果我制作了一个应用程序,并且某个视图在默认情况下首先打开,并且决定要更改首先打开的视图,我将如何执行此操作?该操作由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;
}
- (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;
}
您所要做的就是更改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
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (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;
}