title: hide / show tab bar when push / back. swift
body: <p><strong>Answer: 
  Use self.tabBarController?.tabBar.hidden instead of hidesBottomBarWhenPushed in each view controller to manage whether the view controller should show a tab bar or not.</strong> </p>
  
  <pre><code>override func viewWillAppear(animated: Bool) {
      self.tabBarController?.tabBar.hidden = true/false
  } 
  </code></pre>
  
  <hr>
  
  <p>I want</p>
  
  <p>view controller 1: tab bar should be showed</p>
  
  <p>view controller 2: tab bar should be showed</p>
  
  <p>view controller 3: tab bar should not be showed.</p>
  
  <p>view controller 4: tab bar should not be showed.</p>
  
  <p>I wrote</p>
  
  <pre><code>// prepareForSegue in view controller 1, 
      let upcoming = segue.destinationViewController as! viewcontroller3
      upcoming.hidesBottomBarWhenPushed = true
  
  // in view controller 3,
      func clickOnButton(button: UIButton) {
          self.hidesBottomBarWhenPushed = false
          self.performSegueWithIdentifier("viewController2", sender: self)
          self.hidesBottomBarWhenPushed = true
      }
      override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
          if segue.identifier == "viewController2" {
              let upcoming = segue.destinationViewController as! viewController2
              upcoming.hidesBottomBarWhenPushed = false
          }
      }
  // prepareForSegue in view controller 2
      let upcoming = segue.destinationViewController as! viewController4
      upcoming.hidesBottomBarWhenPushed = true
  </code></pre>
  
  <p>if 1 -> 3 then back to 1, works.</p>
  
  <p>if 1 -> 3 -> 2 then back to 3 and back to 1, works.</p>
  
  <p>if 2 -> 4, then back to 2, works.</p>
  
  <p>if 1 -> 3 -> 2 -> 4 then back to 2, tab bar is not showed. Wondering why. Any suggestions or some explanation of hidesBottomBarWhenPushed as it confuses me a lot</p>
  
  <p><a href="https://i.stack.imgur.com/N0J48.png" rel="noreferrer"><img src="https://i.stack.imgur.com/N0J48.png" alt="enter image description here"></a></p>