2010-11-03 22 views
1

如何將NavigationController作爲根視圖安裝在選項卡欄視圖中?如何將NavigationController作爲根視圖安裝在選項卡欄中?

在我的應用程序中:didFinishLaunchingWithOptions:方法我創建了一個標籤欄界面,將該窗口的rootViewController設置爲tabBarController。

現在,在我的一個標籤欄視圖中,我想在頂部添加一個導航欄。我怎樣才能做到這一點?

我應該繼承導航控制器嗎?

感謝

+1

不要忘記接受答案。 – ardochhigh 2012-11-09 14:38:43

回答

0

你必須先創建一個應用程序的UITabBarController,然後去的MainWindow.xib文件。默認情況下會創建兩個選項卡視圖。

檢查標籤欄的屬性屬性並將視圖更改爲RootViewController。您必須將類名和xib文件名設置爲RootViewController。

1

您可以在Interface Builder中執行此操作。用導航控制器替換標籤欄控制器內的視圖控制器。然後將視圖控制器的類和Nib名稱(在導航控制器內)設置爲您的根類。

2

這聽起來像你在代碼中做的,而不是IB,所以這裏是你可以做的。

// First create your RootViewController: 
UIViewController *rootViewController = [[UIViewController alloc] init]; 
// Then add the rootViewController to a UINavigationController 
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; 
// Now your RootViewController is a UINavigationController 
// Add it to your UITabBarController 
[tabBarController.viewControllers addObject:navigationController]; 
// You can now get rid of the RootViewController and UINavigationController 
[rootViewController release]; 
[navigationController release]; 
+0

謝謝!我正在嘗試以編程方式與IB進行比較。非常感謝,這非常有幫助 – iosrookie 2010-11-04 01:33:15

+0

實際上,現在如何在選擇標籤時讓導航控制器顯示出來? – iosrookie 2010-11-04 02:11:10

+0

這應該會自動發生。 tabBarController應該爲你處理這個問題。 – runmad 2010-11-05 15:14:32

相關問題