2012-05-08 180 views
3

enter image description here如何標籤欄控制器添加到拆分視圖控制器應用

根觀點我是很新的iPad的UISplitViewController

我需要在主視圖/左視圖底部添加一個包含3個選項卡的選項卡欄。對於3個選項卡中的每一個,我都有不同的視圖控制器。我還沒有發現在基於分割視圖的應用程序中使用的Tab欄的其他示例。

我在哪裏插入一個標籤欄控制器,以顯示在根視圖的底部?

如何建立連接,以便當我選擇表格單元時,detailItem信息會顯示在Detail View中?選項卡欄已添加到IB的根視圖中。我應該以編程方式添加它嗎?

+1

http://stackoverflow.com/questions/3573452/tabbarcontroller-within-the-rootviewcontroller-of-a-splitviewcontroller和http://stackoverflow.com/questions/7952214/tabbarcontroller-and-splitviewcontroller可能有幫助 – tipycalFlow

+1

哦我以爲你想要整個應用程序。但基本上它是一樣的想法。你可以把你的意見在tabcontroller,然後在你的主控制器中使用tabcontroller –

回答

1

你必須動態地使用UITabBarController。

在.h文件中

的UITabBarController *的TabBar;

in。M檔

在appDidFinish啓動創建對象到類

例如,你有

的Class1和Class2中

在appDidFinishLaunch

的Class1 * OBJ1 = [Class1的頁頭] initWithNibName:@「Class1」bundle:nil]; ** Class2 obj2 = [Class2 alloc] initWithNibName:@「Class2」bundle:nil]; *

//通過默認主導航控制器自帶的模板代碼

//現在你有一個的TabBar

的NSArray * tabViewArray = [[NSArray的頁頭] initWithObjects創建數組:OBJ1,OBJ2, masterNavigationController,nil];

tabBar = [[UITabBarController alloc] init];

[tabBar setViewControllers:tabViewArray];

//現在你必須編輯包含具有的TabBar splitview.viewArray repalce masterNavigataionControler

self.splitViewController.viewControllers =語句[NSArray的arrayWithObjects:TabBar,所以detailNavigationController,零]

試試這個,我希望它能幫助你。

+0

是的,這是我想要... tabbar而不是masterNavigationController – Ranga

3

在您的應用程序委託中添加tabbar控制器,然後將您的視圖控制器添加到tabbar控制器並將窗口rootview控制器設置爲tabbar控制器。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 
self.tabbar=[[UITabBarController alloc] init]; 

    self.vc1 = [[vc1 alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; 
    // do the same to other VCs 
    self.tabbar.viewControllers=[NSArray arrayWithObjects:vc1,vc2,vc3,vc4, nil]; 


self.window.rootViewController = self.tabbar; 

[self.window makeKeyAndVisible]; 
return YES; 

}

我希望它能幫助:-)

+0

哦,我以爲你想要整個應用程序。但基本上它是一樣的想法。你可以把你的意見在tabcontroller,然後使用您的主控制器中的tabcontroller –

0

所有你需要做的就是初始化uispliviewcontroller的第一個參數爲視圖的TabBar,而不是一個視圖,或者您可以使用uisegmentedcontrol。

相關問題