问题
Here is the setup of my app:
Navigation-
-loginVC -if login is valid, pushes segue to-
tab bar controller with 3 tabs:
-in the first tab, is a profile display which modal pushes to a profile editor(not
issue here)
-second tab is a searchVC that pushes to a tableVC that shows results. This is
where the tab bar disappears
-The third view is just a VC for updating the database this is linked to.
This is literally how it works on the storyboard, and I've made sure the segue from the searchVC to the tableVC, is a push segue.
How can I keep the tab bar controller from disappearing on this second view.
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/15915930/my-tab-bar-controller-disappears-after-a-push-segue