Reputation: 21
While pulling down to refresh, the controller target method is not being called.
Why is this issue happening?
override func viewDidLoad() {
super.viewDidLoad()
scrollview.alwaysBounceVertical = true
scrollview.bounces = true
refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(didPullToRefresh), for: .valueChanged)
self.scrollview.addSubview(refreshControl)
}
@objc func didPullToRefresh() {
print("Refersh")
// For End refrshing
refreshControl.endRefreshing()
}
Upvotes: 2
Views: 2137
Reputation: 82766
iOS 10 > UIScrollView has a refreshControl property. This refreshControl will appear when you create a UIRefereshControl and assign it to this property. No need to add UIRefereshControl as a subview for scroll.
func configureRefreshControl () {
// Add the refresh control to your UIScrollView object.
myScrollingView.refreshControl = UIRefreshControl()
myScrollingView.refreshControl?.addTarget(self, action:
#selector(handleRefreshControl),
for: .valueChanged)
}
@objc func handleRefreshControl() {
// Update your content…
// Dismiss the refresh control.
DispatchQueue.main.async {
self.myScrollingView.refreshControl?.endRefreshing()
}
}
Upvotes: 3