Occasionally my table view won\'t be connected to a service to refresh, and in that case, I don\'t want the UIRefreshControl to be present.
After I add it in viewDid
An old question, but I was looking for an answer and nothing worked exactly like I wanted.
This is what worked for me:
Swift 4
func createRefreshControl() {
refreshControl = UIRefreshControl()
refreshControl?.addTarget(self, action: #selector(self.myTableRefreshFunction), for: UIControlEvents.valueChanged)
refreshControl?.tintColor = UIColor.white
refreshControl?.endRefreshing()
}
func removeRefreshControl() {
refreshControl?.removeTarget(self, action: #selector(self.myTableRefreshFunction), for: UIControlEvents.valueChanged)
refreshControl = nil
}
I call createRefreshControl() when I want the control created, and removeRefreshControl when I want it removed.
I had to remove the same target I initially added to the refresh control, otherwise it would refresh one time before it was actually removed.