How to segue to a specific view controller inside a tab bar controller with losing the tab bar? - ios

Currently I have a tab bar controller that is connected to various navigation controllers like this:
I'm trying to navigate from one view controller to another view controller that is in a separate navigation controller. The only way I've been able to figure out how to keep the tab bar from disappearing is to create a modal segue to the original tab bar controller. The only problem doing this it automatically goes to the default tab bar viewcontroller and not the one I'm trying to reach.

Related

How do I create a "back" button on a View Controller that was initiated from a UITab Bar?

How do I create a "back" button on a View Controller that was initiated from a UITab Bar?
I am initiating the View Controller form the UI Tab Controller. How do I add a back button?
The short answer is "don't". Apples HIG (Human Interface Guidelines) say that when you use a tab bar controller, it should be the top-level navigational control of your app.
You could have one of the tabs contain a navigation controller, and that child view controller could have a navigation bar that includes a back button, but you should not have the tab bar controller be a child of a navigation controller.
If you wanted to violate Apples HIG and make the root level view controller be a navigation controller that contained a tab bar controller you could do that but it would make for a confusing interface. You'd make the root view controller of your app a navigation controller. Then one of the view controllers you pushed onto that navigation controller would be a tab bar controller. When you pressed the back button the navigation controller would pop that navigation controller off the stack and leave you with whatever view controller was under the tab bar controller.

Call master view controller from within detail view of split view controller

I have a tab bar controller with 3 tabs, each embedded within its own navigation controller. This works great, but now I’m trying to put the entire tab bar controller within a split view controller.
The problem is the navigation on the master view for the split view controllers hides the existing navigation for the views inside the tab bar controller. If I hide the master view navigation, I get my tab bar controller navigation back but then I have no way of getting back to the master list. I can add the button back in programmatically but it only works on the iPad.
navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem()
navigationItem.leftItemsSupplementBackButton = true
I also tried playing around with the various options for preferredDisplayMode, but again, this only works on the iPad. It has no effect on the iPhone. I can add in a custom button programmatically to the view controller within the tab view controller and call an action from there, but I don't know what action to call. I tried calling the action on the displayModeButtonItem:
splitViewController?.displayModeButtonItem().action
That didn't work either. I would like to be able to just programmatically add back in the behavior of the back button that the split view controller adds on the iPhone.
I ended up scrapping the split view controller and just using anther tab. However I had a similar problem in another app and I figured out a kind of hacky solution. I embedded the tab bar controller itself inside a navigation controller. This causes multiple navigation controllers to appear so I did a check in viewWillAppear to hide whichever navigation controller is causing the issue.
if let hidden = tabBarController?.navigationController?.navigationBarHidden {
if hidden == true {
tabBarController?.navigationController?.navigationBarHidden = false
}
}
This app has a split view controller as the root view controller and then tab bar controllers in both the master and detail views. Every view is embedded in a navigation controller and I just show or hide the navigation bar depending on if I have a duplicate.

Tab Bar Controller is not in all UIViewControllers

I just created a tab bar controller in my project with 4 tabs in total.
It works fine between the 4 UIViewControllers.
However when I navigate to another UIViewController which is not one of the 4 tabs, the tab bar disappears.
I want it to be seen in every page. How can I do this?
Ok.
The way this is done is by using navigation controllers on each tab.
So, you have your tab bar controller. Then each tab has a navigation controller first and the root view controller of the navigation controller is the page you want in that tab.
Now when you use a push segue the navigation controller pushes the new page and the tab bar controller remains in place.

Create a TabBar Controller with a Master-detail template?

I created master-detail template for the ipad application and now I want to add Tab Bar to either master view or detail view. I can easily add tab bar controller using editor->embed in ->tab bar controller. However when I run application tab bar is not showing.
Tab bar is showing in storyboard but I am also unable to add extra tab bar items. What am I doing wrong thanks?
You should embed the navigation controller (of either the master or detail VC) in a tab bar controller, then delete the connection between the split view controller and that navigation controller. Finally, remake the connection from the split view controller to the tab bar controller. You'll also need to make several code changes, because the template code refers to the detail controller by its hierarchy in the split view controller, which will now be different.

Navigation bar from tab bar controller hides child's nav bar

I am confused with behavior, I have Tab Bar Controller ( I enter on this controller from simple view controller which is embedded in navigation controller). I am confused why is that navigation bar from tab is covered up child navigation bar.
When I start app and I enter at Browse Controller I cannot see Browse title, neither nav bar items which I added programmatically. Can somebody give me clue what is wrong ( I am new to this, I connect with push segue from tab to browse).
Your problem appears to be the same as the one I addressed here:
Push segue from a view controller controlled by UITabBarController
What's happening is that your first NavigationController is creating a Navigation stack. Then you push-segue a TabViewController. That is added to the Nav stack, along with each of it's contained view controllers. However, when you PUSH SEGUE from one of those view controllers to some other view controller, the original navigation controller's stack is the one you are pushing on to. This is not contained inside the tab view controller, so the pushed view controller has no relationship with that tab view controller, just the original navigation controller stack. Therefore the tabs are not present.
The answer is to embed each of the tab controller's view controllers in a new navigation controller, and push on from those. The original navigation controller is just messing things up here...

Resources