我在一个应用程序中有一个Tab View Controller作为我的根控制器,它由3个选项卡组成,我们称它们为View A,View B,View C.
我想在我的应用程序启动后立即加载这些标签,我认为它可以在didFinishLaunchingWithOptions
函数内完成,但我不完全确定,有人知道该怎么做吗?
由于
答案 0 :(得分:0)
出于这些目的,我使用了这种方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
UITabBarController *tabBarController = [[UITabBarController alloc] init];
rootView = [[SGMenuViewController alloc] init];
UIViewController *tab1VC = [[UIViewController alloc] init];
UIViewController *tab2VC = [[UIViewController alloc] init];
UIViewController *tab3VC = [[UIViewController alloc] init];
UIViewController *tab4VC = [[UIViewController alloc] init];
navController = [[UINavigationController alloc] initWithRootViewController:rootView];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:tab3VC];
NSArray* controllers = [NSArray arrayWithObjects:navController, tab2VC, secondNavController, tab4VC, nil];
tabBarController.viewControllers = controllers;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
您基本上创建了一个UITabBarController
并将所有视图放在那里。如果需要在所选选项卡中推送/弹出视图,则可以创建UINavigationController
。在上面的示例中,只有1st
和3rd
标签包含UINavigationController
,因此我可以使用self.navigationController pushViewController:
。