I am trying to set up a pull to refresh function. The refresh works like it should. I set up the refreshControl in the followig way:
let refreshControlAnimation = UIRefreshControl()
self.refreshControl?.addTarget(refreshControlAnimation, action: #selector(handleRefresh(refreshControl:)), for: UIControlEvents.valueChanged)
self.tableView?.addSubview(refreshControlAnimation)
I set up a target and execute the handleRefresh function with a pull.
func handleRefresh(refreshControl: UIRefreshControl) {
DataController().fetchDataLive(mode: "get", completionHandler: { success in
self.tableView.reloadData()
refreshControl.endRefreshing()
})
}
However, if I pull the refresh animation gets executed but it doesn't end at the time it should. Like you can see on the picture, the animation is still getting executed under the section header.
But it should be cleared sooner, like in this image.
Why is my endRefreshing function not called sooner?
Got your problem. Refresh control should not be added as a subview, because swift has already done a provision of adding it to the tableview/tableviewcontrollers.
use:-
self.tableView.refreshControl = yourRefreshControl