title: Refresh Single View Controller in Container View
body: <p>I need help refreshing a single view controller in a container view by passing a variable value to it. I have a storyboard which contains a view controller with a container view. See the following image:</p>
  
  <p><a href="https://i.stack.imgur.com/KKgEp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KKgEp.png" alt="Container View"></a></p>
  
  <p><strong>Total Sales by Company Users</strong> is changing by picker view controller, means it will refresh my view controller for different data.</p>
  
  <p>Now, I'm adding my view controller in this container view of <code>DashbordVC</code> programatically by using following code:</p>
  
  <pre><code>var previousViewController : UIViewController?
  var selectedIndex : Int = 0
  
  // TopSalesVC - Instantiate ViewController
  private lazy var topSalesVC: TopSalesVC = {
      var vc = TopSalesVC.viewController()
      self.addChildViewController(vc)
      return vc
  }()    
  
  // Methods
  override func viewDidLoad() {
      super.viewDidLoad()
      self.setupView()
  }
  
  //------------------------------------------------------------------------------
  
  func setupView() {
  
      self.previousViewController = self.topSalesVC
      self.add(asChildViewController: self.topSalesVC)
  }
  
  //------------------------------------------------------------------------------
  
  private func add(asChildViewController viewController: UIViewController) {
  
      self.addChildViewController(viewController)
      self.containerView.addSubview(viewController.view)
  
      viewController.view.frame = self.containerView.bounds
      viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
      viewController.didMove(toParentViewController: self)
  }
  
  //------------------------------------------------------------------------------
  
  private func remove(asChildViewController viewController: UIViewController) {
      viewController.willMove(toParentViewController: nil)
      viewController.view.removeFromSuperview()
      viewController.removeFromParentViewController()
  }
  </code></pre>
  
  <p>This code works for when the view loads, but when I change for picker view controller row and click on the Done button, it's does nothing.</p>
  
  <p>Now my code for picker view <code>didSelect</code> row as follows:</p>
  
  <pre><code>override func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
      self.selectedIndex = row
  }
  </code></pre>
  
  <p>I have the Done button in the toolbar of picker view. So when I click on it, it executes the following code:</p>
  
  <pre><code>@IBAction func btnDoneClicked(_ sender: UIBarButtonItem) {
  
      BaseVC.isPickerOpen = false
  
      self.showPicker(false) { (success) in
  
          if self.previousViewController != nil {
              self.remove(asChildViewController: self.previousViewController!)
          }
  
          switch self.selectedIndex {
  
          case 0:
              .....
              .....
              break
  
          case 1:
              .....
              .....
              break
  
          case 2:
              .....
              .....
              break
  
          case 3:
              .....
              .....
              break
  
          case 4:
              self.topSalesVC.salesBy = .invoiceByCustomer
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          case 5:
              self.topSalesVC.salesBy = .invoiceByUser
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          case 6:
              self.topSalesVC.salesBy = .supplier
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          case 7:
              self.topSalesVC.salesBy = .manufacturer
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          case 8:
              self.topSalesVC.salesBy = .masterProduct
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          case 9:
              self.topSalesVC.salesBy = .user
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          case 10:
              self.topSalesVC.salesBy = .customer
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          case 11:
              self.topSalesVC.salesBy = .customerTag
              self.previousViewController = self.topSalesVC
              self.add(asChildViewController: self.topSalesVC)
              break
  
          default:
              break
          }
      }
  }
  </code></pre>
  
  <p>With the above method, from cases 4 to 11 which are using the same view controller, just changes its variable value and adds it to container view. </p>
  
  <p>So my issue is that when I change the picker view value to refresh data for a single view controller, it has no effect on my view controller. Displays the same data and initial state. </p>
  
  <p>I have checked TopSalesVC and there the code is working absolutely fine. So there is no issue with TopSalesVC's Code.</p>
  
  <p>Please help me to fix this issue.</p>