title: Number of rows in section error Swift
body: <p>I have a tableview with two custom-cell xibs.</p>
  
  <p>The first xib only contains uilabel and the second one only uibutton.</p>
  
  <p>Once the uibutton is clicked the <code>someTagsArray</code> (array which i use for count in numberOfRows function) is appended and new rows should be inserted, but instead i'm getting this nasty error</p>
  
  <blockquote>
    <p>Invalid update: invalid number of rows in section 0.  The number of
    rows contained in an existing section after the update (8) must be
    equal to the number of rows contained in that section before the
    update (4), plus or minus the number of rows inserted or deleted from
    that section (0 inserted, 0 deleted) and plus or minus the number of
    rows moved into or out of that section (0 moved in, 0 moved out).</p>
  </blockquote>
  
  <p>Here is my code (numberOfRowsInSection)</p>
  
  <pre><code>     func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt;    
  Int {
          return someTagsArray.count + 1
      }
  </code></pre>
  
  <p>cellForRowAtIndexPath</p>
  
  <pre><code>func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell     {
  
          if(indexPath.row &lt; someTagsArray.count){
              var cell:TblCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! TblCell
  
              cell.lblCarName.text = linesmain["start"]![indexPath.row]
  
              return cell
  
          } else {
            var celle:vwAnswers = self.tableView.dequeueReusableCellWithIdentifier("cell2") as! vwAnswers
              celle.Answer1.setTitle(answersmain["start"]![0], forState:UIControlState.Normal)
  
  // answertitle is a global string variable                
  
              answertitle1 = "\(celle.Answer1.currentTitle!)"
  
              return celle
  
          }}
  </code></pre>
  
  <p>and finally the function code which crashes the app</p>
  
  <pre><code>func insertData(){
  
  // appending the array to increase count
  
      someTagsArray += linesmain[answertitle1]!
  
      tableView.beginUpdates()
      let insertedIndexPathRange = 0..&lt;self.linesmain[answertitle2]!.count-4
      var insertedIndexPaths = insertedIndexPathRange.map { NSIndexPath(forRow: $0, inSection: 0) }
      tableView.insertRowsAtIndexPaths(insertedIndexPaths, withRowAnimation: .Fade)
  
      tableView.endUpdates()
  }
  </code></pre>
  
  <p>Thank you guys.</p>