title: How to reload UITableView from different controller
body: <p>I am attempting to make a to-do app with a controller for both &quot;this week&quot; and &quot;next week.&quot; (Objects with a date in the current week will be shown in the <code>thisWeek</code> view controller, while objects with a date next week will be shown in the <code>nextWeek</code> view controller. However, sometimes objects will not appear in the table until the app restarts, and I'm not sure why this is happening or how to fix it.</p>
  <p>My theory is that each table in the different controllers needs to be reloaded each time data is added/changed. I just don't know how to access the table from a different controller than the one I am in.</p>
  <p><strong>Attempt 1</strong> I tried to use a singleton that looked like this:</p>
  <pre><code>class ToDoTables {
      private init() {}
  
      static let shared = ToDoTables()
  
      lazy var thisTable: UITableView = {
          let thisWeek = UITableView()
  
          return thisWeek
      }()
      
      lazy var nextTable: UITableView = {
          let nextWeek = UITableView()
  
          return nextWeek
      }()
  }
  </code></pre>
  <p>then to be called like:</p>
  <p><code>let thisTable = ToDoTables.shared.thisTable</code></p>
  <p>However this did not work because I initially created the table using storyboard and just used an IBOutlet in the controller, and couldn't find way to keep the outlet and also use singleton. Next, I tried to remove the outlet and just use the code above. When I simulated the app, it crashed because the outlet couldn't be found or something like that (which was expected).</p>
  <p><strong>Attempt 2</strong>
  I tried to access the other controller's table by creating an instance of the vc and accessing the table that way:</p>
  <p><code>NextWeekController().nextTable.reloadData()</code></p>
  <p>but got an error that said &quot;Unexpectedly found nil while implicitly unwrapping an Optional value&quot;</p>
  <p><strong>So</strong> I'm not sure if that is my tables need to be reloaded each time, or if it is something else.</p>
  <hr />
  <p>Overview of non-functioning operations (an app restart is needed, or the controller/table needs loaded again):</p>
  <ul>
  <li><p>something created in the nextWeek controller with a date in the current week will not appear</p>
  </li>
  <li><p>when an object in created in nextWeek controller, then date is changed from next week to this week</p>
  </li>
  <li><p>something created in the thisWeek controller with a date in the next week will not appear</p>
  </li>
  <li><p>when an object in created in thisWeek controller, then date is changed from this week to next week</p>
  </li>
  </ul>