Using UITabBarController with UINavigationControll

2020-05-08 08:23发布

问题:

I am making an app which requires a use of a UITabBarController along with UINavigationController. I have made the following flow in storyboard.

See image

Now the first question is that is this accepted by Apple, as there are too many discussions for the same.

The other matter of concern is that is it possible to eliminate any UINavigationController and still get the same flow of the app? The main thing required is to have the SAME tab bar and navigation bar on all sub tabs of the tabs. One point to be noted is that if I remove the second UINavigationController then my app navigates directly from sub tab to home view controller on clicking back button.

I have been stuck on this since hours now. I am new to iOS app development and have never uploaded any app to the app store. Any help would greatly valued.

EDIT :

I put the second navigation controller as shown in the answers - see this flow, But because I have a navigation controller before the HomeViewController, so I am getting a navigation bar at the top and then some empty space below that(exactly equal to the top navigation bar) and then the page contents on runtime. Any solution to this?

回答1:

Yes, it is acceptable by Apple.

But View hierarchy is not managed correctly. In your case Tab bar will be the root view controller for 2nd navigation controller.

Also, Tab and sub tab you are pushing will be part of 2nd navigation controller.

That's the reason you are getting back on Home view controller.

It's good practice to keep navigation controller to each Tab to manage it's sub-tab hierarchy.

You could present tab bar controller or setviewcontroller from Home View controller.



回答2:

First embed tab bar controller as in this image and the embed navigation bar controller as in this image finally this will look like