title: Scrolling to Bottom of UITableView When Messages Load
body: <p>I'm trying to figure out how to scroll to the bottom of the UITableView once the messages from the database load into it. I've tried using <code>tableView.setContentOffset(CGPointMake(0, CGFloat.max), animated: true)</code> but my table goes from having all the messages in it to nothing at all. I've also tried     </p>
  
  <pre><code>var iPath = NSIndexPath(forRow: messagesArray.count - 1, inSection: 0)
  tableView.scrollToRowAtIndexPath(iPath, atScrollPosition: UITableViewScrollPosition.Bottom, animated: true)
  </code></pre>
  
  <p>but I get a <code>EXC_BAD_ACCESS code = 1</code>. Any help would be appreciated.</p>
  
  <p>EDIT:</p>
  
  <p>I'm putting this code in my viewDidAppear() function right after Parse finds the data from the query.findObjectsInBackgroundWithBlock(...), not sure if that makes a difference or not.</p>
  
  <p>Here's the query code:</p>
  
  <pre><code>    query.findObjectsInBackgroundWithBlock { (object, error) -&gt; Void in
                      if (error == nil) {
                          for var i = 0; i &lt; object!.count; i++ {
                              var messageObject = Messages()
  
                              messageObject.messageID = object![i]["messageID"] as! String
  
                              println("MESSAGE ID")
                              println(messageObject.messageID)
  
                              messageObject.messageText = object![i]["message"] as! NSString as String
  
                              println("MESSAGE TEXT")
                              println(messageObject.messageText)
  
                              messageObject.recipientID.append(object![i]["recipientID"] as! NSString as String)
  
                              println("RECIPIENT")
                              println(messageObject.recipientID[0])
  
                              messageObject.senderID = object![i]["senderID"] as! NSString as String
                              messageObject.timeStamp = object![i]["timeStamp"] as! NSString as String
  
                              println("TIMESTAMP")
                              println(messageObject.timeStamp)
  
                              dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
                                  self.messagesArray.append(messageObject)
                              })
                          }
  
  
                          self.loadObjects()
                          self.tableView.reloadData()
                          self.tableView.setContentOffset(CGPointMake(0, CGFloat.max), animated: true)
                      }
      }
  </code></pre>