2
我有一個選項卡視圖控制器作爲我的根控制器在一個應用程序中,它由3個選項卡組成,我們稱它們爲視圖A,視圖B,視圖C. 我想在應用程序啓動後立即加載這些選項卡,我認爲它可以在didFinishLaunchingWithOptions
函數內完成,但我不完全確定,有誰知道該怎麼做?如何在應用程序開始時加載視圖控制器?
感謝
我有一個選項卡視圖控制器作爲我的根控制器在一個應用程序中,它由3個選項卡組成,我們稱它們爲視圖A,視圖B,視圖C. 我想在應用程序啓動後立即加載這些選項卡,我認爲它可以在didFinishLaunchingWithOptions
函數內完成,但我不完全確定,有誰知道該怎麼做?如何在應用程序開始時加載視圖控制器?
感謝
對於這類目的的我用這個方法:
- (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:
。