title: Refreshing Child Controllers with Segmented Control
body: <p>I have parent View Controller containing two Container Views and a segmented control that switches between the two views. Each Container View displays a tableView. The two child view controllers are called printingView and completedView.</p>
  <p>A user can mark an item as complete and it is removed from the printingView tableView and displayed on the completedView tableView. The issue I have is refreshing the completedView tableView when the segmentedControl switches over to display that view. As of now, when item is removed from printingView, I need to navigate to another page and come back to PrintJobs ViewController in order to see the item appear in completedView.</p>
  <p>As implemented, the two views are hidden and shown appropriately. Since the views are still active on the page, the child tableView does not update when the segmented controller is switched. How can I implement the child tableviews so that it reloads when the segmentedControl is invoked?</p>
  <p><strong>Parent VC</strong></p>
  <pre class="lang-swift prettyprint-override"><code>class PrintJobsVC: UIViewController {
  
      @IBOutlet weak var printingView: UIView!
      @IBOutlet weak var completedView: UIView!
  
      var printer:PrinterDisplay? // passed from the VC before via segue
  
      @IBAction func toggleSegmentedController(_ sender: UISegmentedControl) {
          switch sender.selectedSegmentIndex {
          case 0:
              // PrintingView
              setView(view: printingView, hidden: false)
              setView(view: completedView, hidden: true)
  
          case 1:
              // CompletedView
              setView(view: printingView, hidden: true)
              setView(view: completedView, hidden: false)
  
          default:
              print(&quot;hit default case of toggleSegmentedController&quot;)
              setView(view: printingView, hidden: false)
              setView(view: completedView, hidden: true)
          }
      }
  
      override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
          if segue.identifier == &quot;PrintingSegue&quot;, let nextVC = segue.destination as? IndividualPrintingVC {
              print(&quot;individualPrinting segue&quot;)
              nextVC.printer = printer
          } else if segue.identifier == &quot;CompletedSegue&quot;, let nextVC = segue.destination as? IndividualCompletedVC {
              print(&quot;completedSegue&quot;)
              nextVC.printer = printer
          }
      }
  
      func setView(view: UIView, hidden: Bool) {
          UIView.transition(with: view, duration: 0.3, options: .transitionCrossDissolve, animations: {
              view.isHidden = hidden
          })
      }
  
  }
  </code></pre>
  <p><strong>Child PrintingVC (CompletedVC has the same layout)</strong></p>
  <pre><code>class PrintingVC: UIViewController {
      @IBOutlet weak var tableView: UITableView!
      var printer:PrinterDisplay?
      var printingArray:[PrintingDisplay] = []
      
      override func viewDidLoad() {
          super.viewDidLoad()
          
          tableView.delegate = self
          tableView.dataSource = self
          getCoreData() // retrieves from core data and stores in printingArray
      }
      
      override func viewWillAppear(_ animated: Bool) {
          DispatchQueue.main.async { self.tableView.reloadData() }
      }
  }
  
  // tableview methods
  extension PrintingVC: UITableViewDelegate, UITableViewDataSource {
      // set up how many rows are in the tableview
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return printingArray.count
      }
      
      // sets up a cell in the tableview
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCell(withIdentifier: &quot;PrintingCell&quot;, for: indexPath as IndexPath) as! PrintingTableViewCell
          
          let item = printingArray[indexPath.row]
          // setup cell parameters
  
          return cell
      }
  }
  
  // mark the item as complete, remove from printingArray, modify Core Data
  extension PrintingVC: PrintingTableViewCellDelegate {
      func markCompleted(row: Int, indexPath: IndexPath) {
          let item = printingArray[row]
          // confirm that the user wants to complete print
          let alert = UIAlertController(title: &quot;Are you sure?&quot;, message: &quot;\(item.item) will be marked as completed. It can be found in the printer's individual page&quot;, preferredStyle: .alert)
          alert.addAction(UIAlertAction(title: &quot;OK&quot;, style: .default, handler: {action in
              self.markCompletedCoreData(uid: item.uid)
              self.printingArray.remove(at: row)
              self.tableView.deleteRows(at: [indexPath], with: .fade)
          }))
          alert.addAction(UIAlertAction(title: &quot;Cancel&quot;, style: .cancel, handler: nil))
          self.present(alert, animated: true)
      }
  }
  </code></pre>