Skip to content

Instantly share code, notes, and snippets.

@willrichman
Last active August 29, 2015 14:07
Show Gist options
  • Save willrichman/f7eb40f2c72f85bb97b6 to your computer and use it in GitHub Desktop.
Save willrichman/f7eb40f2c72f85bb97b6 to your computer and use it in GitHub Desktop.
Refresh control!
/* Taken from stackOverflow http://stackoverflow.com/questions/24475792/how-to-use-pull-to-refresh-in-swift */
self.refreshControl = UIRefreshControl()
self.refreshControl?.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl?.addTarget(self, action: "refreshTweets:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(self.refreshControl!)
func refreshTweets (sender: AnyObject) {
NetworkController.controller.fetchTimeLine(timelineType, isRefresh: true, newestTweet: self.tweets?[0], userScreenname: userTimelineShown) { (errorDescription, tweets) -> Void in
if errorDescription != nil {
//alert the user that something went wrong
self.refreshControl?.endRefreshing()
} else {
println(self.tweets?.count)
var tweetsInterim : [Tweet]? = tweets
tweetsInterim! += self.tweets!
self.tweets = tweetsInterim!
println(self.tweets?.count)
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment