The refresh wheel stops at 95% full, and the refresh will only work if from the very top of the screen you reach the bottom.
lazy var refreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action:
#selector(VFeedVC.refresh(_:)),
for: .valueChanged)
return refreshControl
}()
override func viewDidLoad() {
self.tableView.addSubview(refreshControl)
}
func refresh(_ sender: Any) {
Metric.sendEvent("RefreshFeed")
self.refreshControl.beginRefreshing()
self.getFeeds(self.user.id)
}
func getFeeds(_ userId: Int) {
VNetwork.getFeeds(userId) { feeds in
self.feeds = feeds
self.tableView.isHidden = self.feeds.count == 0
self.configureCells()
self.refreshControl.endRefreshing()
self.tableView.reloadData()
}
}
This works for me on iOS 11:
override func viewDidLoad() {
self.tableView.refreshControl = refreshControl
self.tableView.addSubview(refreshControl)
}
Also, you don't need to explicitly tell the refresh control to begin refreshing, so this is enough:
func refresh(_ sender: Any) {
Metric.sendEvent("RefreshFeed")
self.getFeeds(self.user.id)
}
Also make sure that in the callback for VNetwork.getFeeds(userId) { feeds in
you are on the main thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With