简体   繁体   中英

iOS - Tabbar with navigation controller and back button issue

I have an issue I don't know how to resolve. My Storyboard looks like this:

NavigationController -> ViewController (Start) -> TabBarController

Then I have 5 ViewController connected to the TabBarController and each of them is embedded in a NavigationController .

My issue is when I click in of these embedded ViewControllers to push a view and then click the Back button, it takes me to the root ViewController (Start) but instead I want to go back one step inside the TabBarController .

How can I resolve this?

I believe TabBarController must always be the top-level Controller in your app. From there you can cascade to individual ViewControllers and they can be embedded in NavigationControllers or not. But TabBarController must be your the starting point in the hierarchy.

You can still have your Start VC somewhere under the TabBarController and can either hide tabbar or you can present the Start VC modally (still in viewdidload in full screen without any menus) and then unwind from there back wherever you need.

Your TabBarController Should be the rootViewController of NavigationController,

So the flow of your Storyboard must be like,

    NavigationController -> TabBarController -> ViewControllers

Assuming your heirarchy is as below

NavigationController -> ViewController (Start) -> TabBarController -> NavigationController1
                                                                   -> NavigationController2
                                                                   -> NavigationController3 
                                                                   -> NavigationController4           
                                                                   -> NavigationController5

In each child ViewController you can write

[self.navigationController popViewControllerAnimated:YES];

Hope this solves your problem.

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