如何將NavigationController作爲根視圖安裝在選項卡欄視圖中?如何將NavigationController作爲根視圖安裝在選項卡欄中?
在我的應用程序中:didFinishLaunchingWithOptions:方法我創建了一個標籤欄界面,將該窗口的rootViewController設置爲tabBarController。
現在,在我的一個標籤欄視圖中,我想在頂部添加一個導航欄。我怎樣才能做到這一點?
我應該繼承導航控制器嗎?
感謝
如何將NavigationController作爲根視圖安裝在選項卡欄視圖中?如何將NavigationController作爲根視圖安裝在選項卡欄中?
在我的應用程序中:didFinishLaunchingWithOptions:方法我創建了一個標籤欄界面,將該窗口的rootViewController設置爲tabBarController。
現在,在我的一個標籤欄視圖中,我想在頂部添加一個導航欄。我怎樣才能做到這一點?
我應該繼承導航控制器嗎?
感謝
你必須先創建一個應用程序的UITabBarController,然後去的MainWindow.xib文件。默認情況下會創建兩個選項卡視圖。
檢查標籤欄的屬性屬性並將視圖更改爲RootViewController。您必須將類名和xib文件名設置爲RootViewController。
您可以在Interface Builder中執行此操作。用導航控制器替換標籤欄控制器內的視圖控制器。然後將視圖控制器的類和Nib名稱(在導航控制器內)設置爲您的根類。
這聽起來像你在代碼中做的,而不是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];
不要忘記接受答案。 – ardochhigh 2012-11-09 14:38:43