1

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.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Jargen89
  • 480
  • 1
  • 6
  • 19

2 Answers2

2

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.

Community
  • 1
  • 1
foundry
  • 31,615
  • 9
  • 90
  • 125
  • This is what I've had in mind for a bit now. What I did was render the original nagivation bar hidden, and created the navigation bars for each three. since I am passing data between each view, I created my own nav controllers that take the data and pass it into corresponding views. – Jargen89 Apr 10 '13 at 03:27
  • I think this misuses modal view controllers - not that it doesn't work, but presenting your main interface as a modal controller violates the intended use of modal controllers. From Apple's docs: "The ability to present view controllers is a tool that you have at your disposal for interrupting the current workflow and displaying a new set of views. Most commonly, an app presents a view controller as a temporary interruption to obtain important information from the user. However, you can also use presented view controllers to implement alternate interfaces for your app at specific times." – rdelmar Apr 10 '13 at 03:27
  • The tab bar controller is the main interface not an alternate interface or a temporary interruption. There's nothing wrong with this from an operational standpoint (other than the login controller stays alive thought the whole app). – rdelmar Apr 10 '13 at 03:29
  • yea, but i don't think the login controller being alive is an issue – Jargen89 Apr 10 '13 at 03:32
0

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218