title: Swift – Table view data not reloading after dismissing view controller
body: <p>I have a view in my app called <code>JournalViewController</code> that I'm presenting over my <code>PastSessionsViewController</code>. <code>PastSessions</code> has a table view that the user can tap to edit and bring up the journal.</p>
  
  <p>When the user edits an entry and saves it (saving to CoreData), dismissing <code>JournalViewController</code> I'd like for the table view in <code>PastSessions</code> to reflect those changes and show the updated table cell.</p>
  
  <p>I'm calling <code>tableView.reloadData()</code> in <code>PastSessionsViewController</code> <code>viewDidLoad()</code> but that doesn't seem to be working. I've also added a delegate for <code>JournalViewController</code> to interact with <code>PastSessionsViewController</code> ahead of <code>dismissViewController</code></p>
  
  <p>Here's some code to look at:</p>
  
  <p>In <code>PastSessionsViewController</code>:</p>
  
  <pre><code>class PastSessionsViewController: UIViewController, UITableViewDelegate, JournalVCDelegate {
      weak var tableView: UITableView?
      weak var backButton: UIButton?
  
      let pastSessionsDataSource: PastSessionsDataSource
  
      init() {
          pastSessionsDataSource = PastSessionsDataSource()
          super.init(nibName: nil, bundle: nil)
      }
  
      required init(coder aDecoder: NSCoder) {
          fatalError("init(coder:) has not been implemented")
      }
  
      override func viewDidLoad() {
          super.viewDidLoad()
          let tableView = UITableView()
          tableView.backgroundColor = nil
          tableView.delegate = self
          tableView.dataSource = pastSessionsDataSource
          tableView.registerClass(EntryCell.self, forCellReuseIdentifier: "cell")
          view.addSubview(tableView)
          self.tableView = tableView
      }
  
      override func viewDidAppear(animated: Bool) {
          tableView?.reloadData()
      }
  
      func didFinishJournalVC(controller: JournalViewController) {
          var newDataSource = PastSessionsDataSource()
          tableView?.dataSource = newDataSource
          // tried this ^, but it's causing the app to crash 
  
          // tableView?.reloadData() &lt;- this isn't doing the trick either
          dismissViewControllerAnimated(true, completion: nil)
      }
  
      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
          let editJournalVC = JournalViewController(label: "Edit your thoughts")
          editJournalVC.delegate = self
  
          presentViewController(editJournalVC, animated: true, completion: nil)
      }
  }
  </code></pre>
  
  <p>In <code>JournalViewController</code>: </p>
  
  <pre><code>protocol JournalVCDelegate {
      func didFinishJournalVC(controller: JournalViewController)
  }
  
  class JournalViewController: UIViewController, UITextViewDelegate {
      var delegate: JournalVCDelegate! = nil
  
      func doneJournalEntry(sender: UIButton) {
          journalEntryTextArea?.resignFirstResponder()
  
          ... do some core data saving ...
          delegate.didFinishJournalVC(self)
      }
  }
  </code></pre>
  
  <p>In <code>PastSessionsDataSource</code>:    </p>
  
  <pre><code>   import UIKit
     import CoreData
  
     class PastSessionsDataSource: NSObject {
          var arrayOfEntries = [Entry]()
          var coreDataReturn: [Meditation]?
  
          func prepareEntries() {
            // gets stuff from coredata and formats it appropriately
          }
  
          override init() {
              super.init()
              prepareEntries()
          }
      }
  
      extension PastSessionsDataSource: UITableViewDataSource {
          func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
              return arrayOfEntries.count
          }
  
          func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
              let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! EntryCell
  
              ... set up the labels in the cell ...
  
              return cell
          }
      }
  </code></pre>
  
  <p>Thanks for looking!</p>