🍔 Create a Table view in your interface and drag it to create an outlet
🍔 Create a refresh control object as a global variable :
var refreshControl: UIRefreshControl!
🍔 In the viewDidLoad, initialize your refresh control and add it to your table view
// Initialize the refresh control.
refreshControl = UIRefreshControl()
refreshControl.attributedTitle = NSAttributedString(string: "Refreshing")
refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: UIControlEvents.ValueChanged)
tView.addSubview(refreshControl)
🍔 Implement the refresh method that will be called when the user refreshes your table view
//Method called when we pull to refresh
func refresh() {
//Do Something
//End refresh
self.refreshControl.endRefreshing()
}
🍔 Create a ScrollView in the interface builder and create an outlet
🍔 In the interface builder, select the scroll view and make sure to check "Bounce Vertically" :
🍔 Drag a view inside the Scroll View hierarchy within the interface builder and create an outlet
🍔 Create a refresh control object as a global variable :
var refreshControl: UIRefreshControl!
C. Drag a view inside the Scroll View hierarchy within the interface builder and create an outlet
🍔 In the viewDidLoad, instantiate your refresh control and add it to your scrollView
// 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)
🍔 Implement the refresh method that will be called when the user refreshes your table view:
//Method called when we pull to refresh
func refresh() {
//Do Something
//End refresh
self.refreshControl.endRefreshing()
}