π
Pull To Refresh π
1 - On a Table view
var refreshControl: UIRefreshControl!
// Initialize the refresh control.
refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Refreshing")
refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
tView.addSubview(refreshControl)
//Method called when we pull to refresh
func refresh() {
//Do Something
//End refresh
self.refreshControl.endRefreshing()
}
πΊ
2 - On a UIView
var refreshControl: UIRefreshControl!
C. Drag a view inside the Scroll View hierarchy within the interface builder and create an outlet
// Initialize the refresh control.
refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Refreshing")
refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
//Adding refreshing to scroll view
self.scrollView.addSubview(refreshControl)
//Method called when we pull to refresh
func refresh() {
//Do Something
//End refresh
self.refreshControl.endRefreshing()
}