title: Updating UITableView when returning from edit form, refresh entire table datasource or the row that was edited?
body: <p>I have a UITableView filled with data from a JSON datasource in my <code>viewDidLoad()</code>.  I'm storing this JSON data in a dictionary at the top of my view controller code:</p>
  
  <pre><code>class InventoryListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
  
      @IBOutlet var inventoryListTableView: UITableView!
      let textCellIdentifier = "textCell";
      var warehouseItems: [Inventory] = [];  //array for my items
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          inventoryListTableView.dataSource = self;
          inventoryListTableView.delegate = self;
  
          loadTableViewWithJSON();  //this loads my data into the warehouseItems dictionary created above
  
      }
  ...
  }
  </code></pre>
  
  <p>Here's my <code>loadTableViewWithJSON()</code></p>
  
  <pre><code>func loadTableViewWithJSON() {
          let urlString = "http://url.php";
          let session = NSURLSession.sharedSession();
          let url = NSURL(string: urlString)!;
  
          session.dataTaskWithURL(url) { (data: NSData?, response:NSURLResponse?, error: NSError?) -&gt; Void in
              if let responseData = data {
                  do {
                      let json = try NSJSONSerialization.JSONObjectWithData(responseData, options: NSJSONReadingOptions.AllowFragments) as! Dictionary&lt;String, AnyObject&gt;;
  
                      //                        print(json);
  
                      if let inventoryDictionary = json["inventory"] as? [Dictionary&lt;String, AnyObject&gt;] {
                          //                        print(inventoryDictionary);
  
                          for anItem in inventoryDictionary {
  
                              //                            print(anItem["quantityOnHand"] as? Int);  //works
  
                              if let id = anItem["id"] as? Int, let item = anItem["item"] as? String, let description = anItem["description"] as? String, let quantityOnHand = anItem["quantityOnHand"] as? Int, let supplierId = anItem["supplier_id"] as? Int, let supplierName = anItem["supplierName"] as? String {
  
                                  let item = Inventory(id: id, item: item, description: description, quantityOnHand: quantityOnHand, supplierId: supplierId, supplierName: supplierName);
                                  //                                print(item);
  
                                  self.warehouseItems.append(item);
                              }
                          }
                          //                        print(self.warehouseItems[0].description); //works
                          dispatch_async(dispatch_get_main_queue(), {
                              self.inventoryListTableView.reloadData();
                          })
                      }
                  } catch {
                      print("Could not serialize");
                  }
              }
  
              }.resume()
          }
  </code></pre>
  
  <p>Tapping one of the items segues into another view for editing the item that was tapped.  When the fields are changed and the item edited there is a big green check that calls a rest API and updates the data in my database (that my UITableView gets from).  Now when I click the Back button in my NavigationController it returns to the previous screen with my UITableView, but the values aren't updated.  I've tried running <code>tableView.reloadData()</code> in my <code>viewWillAppear()</code> but nothing works.  I've also tried calling my function that grabs the data from JSON but of course that just adds the updated data to the end of my tableView and I have an old copy of the data, and a fresh underneath. </p>
  
  <p>My question is, should I just clear my UITableView and run my function that grabs the data once more?  Or should I just update the single row with the new data?  I thought updating the single row would be better for less overhead on my restful API.  Or would it be better to detect when I'm coming back from my editing view controller and reload all the data?</p>
  
  <p>I've tried this but it doesn't work:</p>
  
  <pre><code>    override func viewWillAppear(animated: Bool) {
          super.viewWillAppear(animated);
          // loadTableViewWithJSON(); // this duplicates the data in the tableview
          inventoryListTableView.reloadData();
      }
  </code></pre>
  
  <p>And my <code>cellForRowAtIndexPath</code> :</p>
  
  <pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as UITableViewCell;
          let row = indexPath.row;
          cell.textLabel!.text = "\(warehouseItems[row].item) --&gt;  \(warehouseItems[row].quantityOnHand) on hand"
  
          cell.detailTextLabel!.text = warehouseItems[row].description;
  
          return cell;
      }
  </code></pre>