Last active
August 29, 2015 14:07
-
-
Save willrichman/f7eb40f2c72f85bb97b6 to your computer and use it in GitHub Desktop.
Refresh control!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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