I am building an RSS reader using swift and need to implement pull to reload functionality.
Here is how i am trying to do it.
class FirstViewController: UIViewController,
UITableViewDelegate, UITableViewDataSource {
@IBOutlet var refresh: UIScreenEdgePanGestureRecognizer
@IBOutlet var newsCollect: UITableView
var activityIndicator:UIActivityIndicatorView? = nil
override func viewDidLoad() {
super.viewDidLoad()
self.newsCollect.scrollEnabled = true
// Do any additional setup after loading the view, typically from a nib.
if nCollect.news.count <= 2{
self.collectNews()
}
else{
self.removeActivityIndicator()
}
view.addGestureRecognizer(refresh)
}
@IBAction func reload(sender: UIScreenEdgePanGestureRecognizer) {
nCollect.news = News[]()
return newsCollect.reloadData()
}
I am getting :
Property 'self.refresh' not initialized at super.init call
Please help me to understand the behaviour of Gesture recognisers. A working sample code will be a great help.
Thanks.
I suggest to make an Extension of pull To Refresh to use in every class.
1) Make an empty swift file : File - New - File - Swift File.
2) Add the Following
3) In Your View Controller call these methods as :
4) At some point you wanted to end refreshing:
you can use this subclass of tableView:
1 - in interface builder change the class of your tableView to
PullToRefreshTableView
or create aPullToRefreshTableView
programmatically2 - implement the
PullToRefreshTableViewDelegate
in your view controller3 -
tableViewDidStartRefreshing(tableView: PullToRefreshTableView)
will be called in your view controller when the table view starts refreshing4 - call
yourTableView.endRefreshing()
to finish the refreshing