title: How to refresh tableview when user inserts an item into the database?
body: <p>When the user inserts an item into the database and then clicks the back button to return to the tableview, the tableview is not displaying the new item. I have to stop the app, and run it again for the new item to be displayed. My database is working perfectly fine, so i don't think thats the problem.</p>
  
  <p>I do reload the database again in the mainController inside ViewDidLoad(). I also tried doing tableView.reloadData() inside ViewDidLoad() as well and that doesn't do anything.</p>
  
  <pre><code>class MainViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
  
      @IBOutlet weak var tableView: UITableView?
      let mainDelegate = UIApplication.shared.delegate as! AppDelegate
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
          // read from the database
          mainDelegate.readDataFromDatabase()
  
      }
  
      func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
  
          return mainDelegate.people.count
  
      }
  
      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
          let cell = tableView.dequeueReusableCell(withIdentifier: "BookTableViewCell") as! BookTableViewCell
  
          let rowNum = indexPath.row
  
          cell.lblTitle?.text = mainDelegate.people[rowNum].title
          cell.accessoryType = .disclosureIndicator
  
          return cell
      }
  
  
  
  class NewBookItemViewController: UIViewController, UITextFieldDelegate, UINavigationControllerDelegate {
  
      @IBOutlet weak var titletxt : UITextField!
  
      @IBAction func buttonSave(sender: UIButton){
           // step 18b - instantiate Data object and add textfield data
              let person : Data = Data.init()
              person.initWithData(theRow: 0, thetitle: title)
  
              let mainDelegate = UIApplication.shared.delegate as! AppDelegate
  
              // step 18c - do the insert into db
              let returnCode : Bool = mainDelegate.insertIntoDatabase(person: person)      
  
  
          }
  </code></pre>