My Tab bar controller disappears after a push segue

左心房为你撑大大i 提交于 2019-12-02 07:25:58
foundry

The structure should be

loginViewController -->modal segue--> tabBarController
                                        |
                                        |
                                        |-->NavController->Item1ViewController
                                        |
                                        |-->NavController->Item2ViewController
                                        |
                                        |-->NavController->Item3ViewController

At the moment, the 'push' on your second tab item pushes the whole tab bar controller out of the way when you push on from item 2's first viewController.

If you want a nav bar on your loginViewController (for consistency), embed it in it's own navigationController but ensure you don't push on from there: modal segue or present with [self presentViewController:tabBarViewController animated:yes completion:nil]

Each of the tab bar item's nav controller is optional (depends on what navigation you are after, clearly you do want one for item 2) - but you may want one for each item for consistency.

update
@rdelmar suggests that this method of using a login screen as a root view controller - on top of which the rest of the app is 'modally' presented - is a misuse of the modal segue, and suggests modally presenting the login screen on the first tab item instead. I understand the point and will give it some more thought, but likewise I find that alternative a little uncomfortable... tab items should share equal weight in a tabVC - so making the first item present a modal login controller on which the whole app depends doesn't feel like good program flow. If an app requires the user being logged in, I don't see anything wrong with the login somehow underpinning it.

I have a more fully described version of this in an answer here:(How to handle UINavigationControllers and UITabBarControllers iOS 6.1). This also has the advantage that if you offer a logout button from anywhere in your app, an unwind segue back to that first login screen - effectively un-presenting the entire logged-in app stack - will work nicely.

A different solution - which chimes with @rdelmar's - would be to present the login screen modally from the first viewController if that were not in a tab bar controller. This could have worked in my aforementioned answer as the first screen after login was a navController-embedded viewController. However the unwind-to-logout would not have been so clean.

In the end I suspect this is may be just a point of style that we shouldn't get too hung up about so long as flow logic remains robust.

Unless you have another navigation controller that you don't mention, your push is from the navigation controller that's your initial controller. So, pushing from it, puts the tableVC on top of the tab bar controller in the navigation controller's view controllers.

I would suggest that you make the tab bar controller the root view controller of the window. Have the loginVC presented modally from the controller in the first tab (from its viewDidAppear method) so it will appear first when the app launches. The second tab should have a navigation controller as its root controller with searchVC as the navigation controller's root view controller.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!