Tab bar Controller.... Second View Controller doesn't have tab bar items? - swift

I have a tab bar controller that points to several story board references.
One of the references points to a story board (SC1) with two view controllers. On VC1, the tab bar appears, yet on VC2 the tab bar does not when I segue to it programmatically. Perhaps it's more accurate to say the tab bar items don't because a light grey bar does appear to be at the bottom of the view.
I have another story board (SC2) with a similar setup yet the tab bar appears on both VC1 and VC2. In this case I segue by clicking on a tableview cell.
In both cases I segue from VC1 to VC2 using a Show (e.g. Push) segue.

it needs to be created as a relationship to the external storyboard reference. the storyboard's VC you'll be referencing must have a tab bar item in it to show app. Plus you can also try create a tab bar controller and add them in code (I have done that in the past).

The issue was a lack of understanding of Tab Bar Controller and the relationship with Navigation View Controllers.
I assumed every child vc embedded in a Tab Bar Controller would display the tabs. In other words..
Tab vc
...vc1
.....vc2
Tab vc only sees vc1. The answer is in the Navigation Controller.
The first vc must be embedded in a Navigation Controller. That vc and all other child vc's go onto the Nav Controller stack... When you call it, every child vc knows that it is embedded in a Tab Vc and will display the tabs.

Related

Why doesn't the first navigationcontroller in my storyboard have an effect on the tableviewcontroller?

My Storyboard is setup as:
UIViewCont
/
NavigationController -> UIViewContr -> UIViewContr ----- UIView Contr
\
NavCont
\
TableViewController
The last three controllers (2 x UIView and 1 x TableView) use "show" segues from three different buttons. And the TableView controller is embedded in the NavCont.
Because the first controller is a NavController every UIViewController has a back button except the TableViewController.
I've been reading up about it but can't figure out why. Other than each Navigation controller is it's own stack and kind of starts again so you can't just navigate back from a 2nd or 3rd navigation controller. But not sure.
Thanks.
Using a navigation controller resets the navigation stack tracking, so your table view does not have a back button because it is effectively a new root. If you create a view controller that the table view segues to, it will have a back button because it is part of the (inner) navigation chain and not the root.
It is not apparent from your example what you are trying to do or why you have the inner navigation controller instead of just relying on the original navigation stack. There is one option you can try. The root view of a navigation stack should have the navigation bar, and you can drag bar button items onto it, allowing you to unwind back to the previous state.

How to navigate back from a navigation controller on the storyboard in xcode

I've got an initial view controller InitialViewController with a button "List" (and a few other random buttons).
Clicking on "List" segues to a UITableViewController that is embedded in a navigation controller. And that is all sweet.
But once the UITableViewController is loaded there is no "back" button to navigate back to InitialViewController.
I was just wondering what my options were. On the storyboard I've used a "Navigation Item" and "Button Bar" and i'll hook that up programmatically to navigate back.
I just wasn't sure if an unwind segue was an option or if anyone had better ideas.
Thanks.
The reason you don't see a back button when your UITableViewController is loaded is because it is the root view controller for the navigation controller that it is embedded in. As such, the NavigationController has no other view controller in the stack that it can go back to.
Instead of the TableViewController, embed your InitialViewController inside a NavigationController and that should add a navigation bar with Back button to your TableViewController.
If you don't want to show the Navigation Bar in your InitialViewController, you can hide it using the following steps:
In your storyboard file, select the InitalViewController
Open the Attributes inspector and set Top Bar to None
Hope this helps!

UIViewController in a UITabBarController without tab bar item

So I have this application where I have a view controller (which I want to appear first when the app starts) and a tab bar controller. I also have other navigation bar controllers that are in the tab bar controller. I want to place my view controller on top of the tab bar controller. Making the tab bar controller the parent of the view controller would be better though.
But take note, I do not want a tab bar item to represent the view controller and I want the tab bar to appear along with the view controller. I do not and would not want to use storyboards as much as possible. How can i achieve this?
I guess the simplest solution would be to use a screenshot of your tabBar and put it in your HomeViewController as a button. In this case you could use your HomeViewController as rootViewController and in the button action you set the TabBarController as the rootViewController.
Root = Home + Button
-->
Root = TabBar
Perhaps you need four buttons, if you want the correct tab to be selected.

How to retain tab bar after modal segue?

I have 3 View controllers in a tab bar. (my 3 icon). I have another view controller that is accessible from one of the 3 via a button. I do not want this extra view controller to show on the tab bar though.
On clicking the button with a push segue nothing happens, with a modal segue it opens the new page, but the tab bar disappears. (Even though I created a relationship from this new view controller to the tab bar).
How do I get the tab bar to remain? I don't really want to set up a navigation controller between my one view and the other (not on the tab bar) because it's not really hierarchal content.
Is modal actually the right segue to use?
Does your views (the views of the 3 views controller) contain the tab bar? If not, you may try transiting from the view to the view of the extra view controller.
see +[UIView transitionFromView:toView:duration:options:completion:]
When you select a Modal segue, the new view is not added as part of the current TabController stack. That's why the tab bar is not visible when you go to this view, and it's why a Push segue does not work for you (you can't push a VC that's not part of the stack).
From the sounds of it, if you want the tab bar to remain visible/useful but don't want to add this VC to the tab bar, what you're really saying is that this VC is a sub-view of one of the original 3 VCs in the tab bar.
In which case you could manage instantiation of your "custom" VC from within one of these original VC's, and add it as a sub-view?
For example if you've got: Tab1, Tab2, Tab3 and ExtraView
in Tab2 VC you would init/alloc SubView and do: [self addSubView:ExtraView.view];
Unfortunately, of course this way you lose Segues, but unless you want to go ahead and set up Tab2 as nested NavigationController in Storyboard, I think that's your best bet.

Tab bar disappears after touching cell in tableview

I have an issue with a tab bar app. I am making a tab bar app with three bars on the bottom. On my my first bar it is a tableviewcontroller. When i ckick on the table view controller it takes me to a different view (which doesn't have the tab bar). When I clicked back to the home screen (which has the tab) the tab bar is gone.If you need a picture i will post it!
You may have set your UITableViewController segue to a modal style. If this is the case, you should change it to a push style.
In order for a push to work, your view controller needs to be in a UINavigationController. In your story board, select your root view controller and embed it into a Navigation Controller like this...