title: Deleting UITableViewCell: NSInternalInconsistencyException?
body: <p>I'm getting an error when I try to delete a cell from my <code>UITableView</code>. I've looked at numerous links (this one for example is what I'm going off of. Below is my code:</p>
  
  <pre><code>var countdownTime = expirDate - currentDate
      timer.setCountDownTime(countdownTime)
      println("Count : \(self.offers.count)")
      timer.startWithEndingBlock { (countdownTime) -&gt; Void in
          //If the times have expired, then delete the row
          self.tableView.beginUpdates()
          self.offers.removeAtIndex(indexPath.row)
          self.tableView.deleteRowsAtIndexPaths([indexPath.row], withRowAnimation: UITableViewRowAnimation.Fade)
          self.tableView.endUpdates()
      }
  timer.start()
  
  func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return offers.count
  }
  //Only one section
  func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
      return 1
  }
  </code></pre>
  
  <p>I want to remove the cell when my timer has completed and the <code>offers</code> array is the array that I use to populate the <code>UITableView</code>. I was going off of this <a href="https://stackoverflow.com/questions/19357874/assertion-failure-uitableview-endcellanimationswithcontext">Assertion Failure -[UITableView _endCellAnimationsWithContext]</a> which I thought would help me delete/insert rows correctly but I still get an error saying: </p>
  
  <p><code>*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'</code></p>
  
  <p>Any help would be appreciated! </p>
  
  <p>EDIT: An issue I might be having that I am trying to delete the cell while I am inserting the cell into the UITableView. I am inserting the cell, setting the cell contents, then deleting the cell if the timer for that cell has existed for over 24 hours. This is bad because the cell will then try to insert the next cell when it thinks that there is 1 cell in the table view. Are there any better ways to do this?</p>
  
  <p>EDIT 2: Code for inserting into table:</p>
  
  <pre><code>           ...//Code to insert into database
      override func viewDidLoad() {
      super.viewDidLoad()
  
      //setupOffers()
  
      setupOffers { (result, offer) -&gt; Void in
          if(result == true){
              //Insert each row one by one.
              var currentCount = self.offers.count
              var indexPaths: [NSIndexPath] = [NSIndexPath]()
              indexPaths.append(NSIndexPath(forRow:currentCount, inSection: 0))
              self.offers.append(offer)
              currentCount++;
  
              //Update based on each table view index.
              self.tableView.beginUpdates()
              self.tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.Bottom)
              self.tableView.endUpdates()
              //Method 2 to update uitableview
  
              //self.tableView.reloadData()
          }
      }
      // Do any additional setup after loading the view, typically from a nib.
      self.tableView.delegate = self
      self.tableView.dataSource = self
      self.tableView.rowHeight = UITableViewAutomaticDimension
      self.tableView.rowHeight = 145.0
  
  }
  </code></pre>