title: Add view controller to container view overwriting view
body: <p>I've tried following numerous examples and other <a href="https://stackoverflow.com/questions/27276561/adding-a-view-controller-as-a-subview-in-another-view-controller">questions</a> on SO. The view controller is being added but it is placing the view container into the view and not the view container. Here is a shot of what I mean.</p>
  
  <p><a href="https://i.stack.imgur.com/AjQIW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AjQIW.png" alt="enter image description here"></a></p>
  
  <p>I have a tab bar on the primary view controller and a container view. When an item on the tab bar is tapped, it is supposed to grab the controller and load it into the container view. Here is the code for how I am doing it.</p>
  
  <pre><code>@IBOutlet weak var tabBar: UITabBar!
  @IBOutlet weak var containerView: UIView!
  var currentViewController: UIViewController!
  var radarViewController: UIViewController!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      // Do any additional setup after loading the view.
      let storyboard = self.storyboard
      let currentViewController = storyboard?.instantiateViewController(withIdentifier: "WeatherCurrentViewController") as! WeatherCurrentViewController
      self.currentViewController = UINavigationController(rootViewController: currentViewController)
      let radarViewController = storyboard?.instantiateViewController(withIdentifier: "WeatherRadarViewController") as! WeatherRadarViewController
      self.radarViewController = UINavigationController(rootViewController: radarViewController)
  }
  func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
      if item.tag == 1 {
          containerView.addSubview(currentViewController!.view)
          currentViewController.didMove(toParentViewController: self)
      }
  
      if item.tag == 2 {
          containerView.addSubview(radarViewController!.view)
          radarViewController.didMove(toParentViewController: self)
      }
  }
  </code></pre>
  
  <p>This is Swift 3. I don't know what it is I am doing incorrectly. Any help is appreciated.</p>
  
  <p>Update</p>
  
  <p>Although I never got the switching of view to work programmatically after numerous changes/tries, I did find another way of using segues with multiple view containers (<a href="https://spin.atomicobject.com/2015/09/02/switch-container-views/" rel="nofollow noreferrer">here</a>. Not the ideal since it ties up more memory but it works.</p>