简体   繁体   中英

Combining single navigation controller with tab bar controller

I want to combine a navigation controller and tab bar controller together and display 3 view controllers via the tab bar.

I can accomplish this if I embed each of the three vcs into its own navigation controller and then add those to the tab bar controller. However there are now three navigation controllers.

But according to the Apple documentation, it is possible to use a single navigation controller: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/CombiningViewControllers.html

To create a combined interface with three tabs that contain custom view controllers and one tab that contains a navigation controller:

1) Create three custom view controllers, one for each tab, and a navigation controller.
2) Select the three custom view controllers and the navigation controller (only the navigation controller scene, not it’s root view controller).
3) Choose Editor > Embed In > Tab Bar Controller.
4) Display the tab bar controller as the first view controller by selecting the option Is Initial View Controller in the Attributes inspector (or present the view controller in your user interface in another way.)

The first sentence in that quote mentions "a navigation controller", ie singular. And in the instructions it say "the navigation controller", also singular.

However when I follow these instructions I end up with a tab bar which contains 4 items, 3 for the view controllers and one for the navigation controller.

If its possible to have a single navigation controller as the Apple documentation says, what's wrong with the Apple instructions for doing so? How can I get three items in the tab bar?

The Apple document is just saying that you can use a navigation controller within a single tab to control navigation within that tab. If you have multiple tabs and want navigation controllers in all of them, then yes you can do that, but the three navigation controllers will be independent.

In other words, you can use both a tab bar and a navigation controller in your app, but not for the same purpose. The tab bar provides the top-level navigation, and the navigation controllers provide navigation lower down. You can't control your top-level navigation with both a tab bar and a navigation controller at the same time.

Here are the Apple Human Interface Guidelines regarding navigation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM