Search code examples
swift3seguehiddentabbar

Swift 3 – Tab Bar Hidden on Segue


Here is my setup (click 'setup' to see picture):

The Problem

When I segue from Blue back to Green, I lose my tab bar and I can't get to Red. I think this is because the segue that I used covered the entire screen and hid the Tab Bar. What segue should I be using? Why doesn't seguing back show the Tab Bar again?

Note that I want to use a button to switch between Green/Blue (so far, only the Show Detail segue works) but I want to use the Tab Bar to switch between Red/Green. I have tried this and this but neither worked for me.

Thanks in advance,

J. Shaw


Solution

  • I'm not clear on how you removed the tab bar from your Blue View Controller, but the way I'm describing below removes it and it will remain on the Green View Controller when you use the back button. The result is you'll be able to move Red VC via the Tab Bar.

    1. Create a new Cocoa Touch Class File... File -> New File. I named it GreenVC and make sure you select UIViewController in the Sub Class Of dropdown.
    2. Replace the contents of GreenVC with the following code:

    import UIKit

    class GreenVC: UIViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
        }
    
        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
            let destinationVC = segue.destination as! UIViewController
            destinationVC.hidesBottomBarWhenPushed = true
        }
    }
    
    1. Click on the yellow circle at the top of the Green View Controller in the Storyboard.
    2. Go to identity inspector and select GreenVC from the Class drop down under Custom Class like so:

    enter image description here

    1. You are done!

    The Storyboard:

    enter image description here