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.
In Swift use this,
If you wants to have pull to refresh in WebView,
So try this code:
Anhil's answer helped me a lot.
However, after experimenting further I noticed that the solution suggested sometimes causes a not-so-pretty UI glitch.
Instead, going for this approach* did the trick for me.
*Swift 2.1
iOS 10 - Swift 3 (Also applicable for iOS 11 - Swift 4)
I would like to mention a PRETTY COOL feature that has been included since iOS 10, which is:
For now, UIRefreshControl is directly supported in each of
UICollectionView
,UITableView
andUIScrollView
!Each one of these views have refreshControl instance property, which means that there is no longer a need to add it as a subview in your scroll view, all you have to do is:
Personally, I find it more natural to treat it as a property for scroll view more than add it as a subview, especially because the only appropriate view to be as a superview for a UIRefreshControl is a scrollview, i.e the functionality of using UIRefreshControl is only useful when working with a scroll view; That's why this approach should be more obvious to setup the refresh control view.
However, you still have the option of using the
addSubview
based on the iOS version:For the pull to refresh i am using
DGElasticPullToRefresh
https://github.com/gontovnik/DGElasticPullToRefresh
Installation
pod 'DGElasticPullToRefresh'
override func viewWillAppear(_ animated: Bool)
And dont forget to remove reference while view will get dissapear
to remove pull to refresh put this code in to your
override func viewDidDisappear(_ animated: Bool)
And it will looks like
Happy coding :)
Others Answers Are Correct But for More Detail check this Post Pull to Refresh
When you’re working with a UITableViewController, the solution is fairly simple: First, Select the table view controller in your storyboard, open the attributes inspector, and enable refreshing:
A UITableViewController comes outfitted with a reference to a UIRefreshControl out of the box. You simply need to wire up a few things to initiate and complete the refresh when the user pulls down.
In your override of viewDidLoad(), add a target to handle the refresh as follows:
refreshControl.endRefreshing()
For more information Please go to mention Link and all credit goes to that post
A Solution with storyboard and swift...
1.) Open your .storyboard file, select a TableViewController in your storyboard and "Enable" the Table View Controller - Refreshing feature in the Utilities.
2.) Open the associated UITableViewController-Class and add the following line into the viewDidLoad-Method.
OR in Swift 2.2:
3.) Add the following Method above the viewDidLoad-Method