title: inserting row at bottom in uitableview swift
body: <p>I'm trying to insert a row in the bottom when user scrolls to bottom of the <code>UITableView</code>. But the problem is, it is inserting the row at the bottom but it takes me back to the first row. How can i stop this from happening? here is my code</p>
  
  <pre><code>        func delay(delay:Double, closure:()-&gt;()) {
              dispatch_after(
                  dispatch_time(
                      DISPATCH_TIME_NOW,
                      Int64(delay * Double(NSEC_PER_SEC))
                  ),
                  dispatch_get_main_queue(), closure)
          }
  
      class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
  
          var tableView:UITableView = UITableView()
          var array:NSMutableArray = ["hey \n2 \n2 \n2 \n2 \n2 \n2","fjcjscsoomc   sample text message big","and this is a small text "]
  
  
  
  
          override func viewDidLoad() {
              super.viewDidLoad()
  
              tableView.frame = CGRectMake(0, 0, phonewidth, self.view.frame.height)
              tableView.delegate = self
              tableView.dataSource = self
              self.tableView.registerNib(UINib(nibName: "CustomCell", bundle: nil), forCellReuseIdentifier: "cell")
              self.view.addSubview(tableView)
  
  self.tableView.addInfiniteScrollingWithActionHandler { () -&gt; Void in
                  delay(2.0, { () -&gt; () in
  
                      self.tableView.beginUpdates()
                      self.array.insertObject("123", atIndex: self.array.count)
                      var nspath = NSIndexPath(forRow: self.array.count - 1, inSection: 0)
                      self.tableView.insertRowsAtIndexPaths([nspath], withRowAnimation: UITableViewRowAnimation.Left)
                      self.tableView.endUpdates()
                      self.tableView.infiniteScrollingView.stopAnimating()
                  })
              }
          }
  
  
          func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
  
  
                  let  cell = tableView.dequeueReusableCellWithIdentifier("cell") as CustomCell
                  cell.labelText.text = array.objectAtIndex(indexPath.row) as String
                  return cell
  
          }
  
  
          func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
                  return array.count
              }
  
      }
  </code></pre>
  
  <p>this code is working fine, it inserts a row at bottom when i scroll down to bottom but after inserting tableView takes me back to the first row.</p>