-
-
Save rahulgautam/eb0fe73eb5c31aaf0b94014aace1daf5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@objc protocol Refreshable | |
{ | |
/// The refresh control | |
var refreshControl: UIRefreshControl? { get set } | |
/// The table view | |
var tableView: UITableView! { get set } | |
/// the function to call when the user pulls down to refresh | |
@objc func handleRefresh(_ sender: Any); | |
} | |
extension Refreshable where Self: UIViewController | |
{ | |
/// Install the refresh control on the table view | |
func installRefreshControl() | |
{ | |
let refreshControl = UIRefreshControl() | |
refreshControl.tintColor = .primaryColor | |
refreshControl.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged) | |
self.refreshControl = refreshControl | |
if #available(iOS 10.0, *) | |
{ | |
tableView.refreshControl = refreshControl | |
} | |
else | |
{ | |
tableView.backgroundView = refreshControl | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment