2011-05-07 60 views
1

我創建已經是三視圖控制器&我想只添加tabBarview控制器的視圖控制器。 視圖控制器低於把視圖控制器中的TabBar的ViewController

第一 - >登錄頁面

二 - >的TabBar視圖控制器

  1)---> Employee View controller 
      2)---> Task View Controller 
      3)----> Home View controller 

我創建上述三種視圖控制器分離。我想使用Interface Builder或編碼將它們添加到標籤欄控制器中。

回答

0

更好的方法是創建一個基於TabBarContoller應用程序和ViewControllers添加到TabbarViewController。

+0

創建一個標籤欄控制器和配置它需要比打開了一個全新的項目,並導入所有現有的代碼和重新配置構建設置,等等 – 2011-05-07 10:05:12

0

路徑很簡單。

IB,在地方,你喜歡你的TabBar控制器,使其具有三個頁面,並設置其視圖控制器類。

或者在代碼,只需用設置爲它的視圖控制器那些三個控制器添加標籤欄控制器。

2

您可以從蘋果的文檔找到更具描述性的例子 - Combined View Controller Interfaces

我假設登錄頁面是你的根視圖控制器在這裏。其中_tabBar_window_loginvVewController是在appDelegate頭文件中全局聲明的。根據您的要求,您也可以在didFinishLaunchingWithOptions方法中本地取_loginvVewController

AppDelgate.h

UIWindow *_window; 
UITabBarController *_tabBar; 
LoginViewController *_loginvVewController; 

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    self.loginvVewController = [[LoginViewController alloc] init]; 

    // Add the tab bar controller's current view as a subview of the window 
    [self.window addSubview:self.loginvVewController.view]; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

- (void)initializeTabbar { 

    /* 
    * Set up controllers for the tab bar controller 
    */ 
    EmployeeViewController *vc1 = [[[EmployeeViewController alloc] initWithTitle:@"View 1"] autorelease]; 
    TaskViewController *vc2 = [[[TaskViewController alloc] initWithTitle:@"View 2"] autorelease]; 
    HomeViewController *vc3 = [[[HomeViewController alloc] initWithTitle:@"View 3"] autorelease]; 

    // View Controller with each Navigational stack support. 
    UINavigationController *navController = [[UINavigationController alloc] 
              initWithRootViewController:vc1]; 

    /* 
    * Set up tab bar controller 
    */ 
    self.tabBar = [[UITabBarController alloc] init]; 
    self.tabBar.viewControllers = [NSArray arrayWithObjects:navController, vc2, vc3, nil]; 

    [self.window addSubview:self.tabBar.view]; 
} 

在我的快速編程馬拉松對於這個問題,我已經採取了按鈕 「點擊這裏!」在登錄頁面 - 一旦你點擊它將用tabbar在你的應用程序內導航你。如果您需要示例項目,請發送電子郵件至[email protected]

經過電子郵件的許多請求 - 我已經創建了演示項目,並在這裏上傳。 https://github.com/Deminem/SimpleTabbarApp--iPhone-

如果你覺得有用請投票。

祝你好運!

+0

它給黑屏時間要少得多。我能做什麼不能理解。 – Sam007 2011-05-07 11:06:24

相關問題