Refreshing table view with a UIRefreshControl in swift
<p>I am working on an iOS app in which I have a UITableView which needs to be refreshed on command. I have added a UIRefreshControl object and hooked up a function to it so that whenever I drag down on the table view, my refresh code is supposed to take place. The code fragment is below: </p>

<pre><code>@IBAction func refresh(sender: UIRefreshControl?) {
    self.tableView.setContentOffset(CGPointMake(0, self.tableView.contentOffset.y-self.refreshControl!.frame.size.height), animated: true)
    sender?.beginRefreshing()

    if (profileActivated) {
        self.matches = []

        let dynamoDBObjectMapper = AWSDynamoDBObjectMapper.defaultDynamoDBObjectMapper()
        let queryExpression = AWSDynamoDBScanExpression()
        queryExpression.limit = 100;

        // retrieving everything
        dynamoDBObjectMapper.scan(DDBMatch.self, expression: queryExpression).continueWithBlock({ (task:AWSTask!) -&gt; AnyObject! in

            if task.result != nil {
                let paginatedOutput = task.result as! AWSDynamoDBPaginatedOutput

                //adding all to the matches array
                for item in paginatedOutput.items as! [DDBMatch] {
                    self.matches.append(item)
                }           
                //code to filter and sort the matches array...            
                self.tableView.reloadData()           
            }
            return nil
        })
        self.tableView.reloadData()       
    }

    sender?.endRefreshing()
    self.tableView.setContentOffset(CGPointMake(0, self.tableView.contentOffset.y - (0.5*self.refreshControl!.frame.size.height)), animated: true)
}
</code></pre>

<p>Unfortunately, this code does not quite work right. Whenever I drag down on the refresh control, my table populates but then immediately goes away, and then refreshes about 10-15 seconds later. I inserted some print statements, and the data is all there, it just does not appear for a long time, and I am having trouble making it appear as soon as it is retrieved. I am new to iOS programming so any help would be appreciated.</p>

<p>Thanks in advance</p>