Pull-To-Refresh
UIRefreshControl providing the refreshing control on ScrollView, TableView and CollectionView. this tutorial we are study how to use UIRefreshControl over the tableview.
UIRefreshControl is use over tableView whenever the webservice data display and reload on tableview.
Full Code of UIRefreshControl + UITableView:
12345678910111213141516171819202122232425262728293031323334353637383940import UIKit
class ViewController: UIViewController , UITableViewDelegate , UITableViewDataSource {
@IBOutlet var refreshtable : UITableView!
var refreshControl = UIRefreshControl()
let data: [String] = ["Apple", "HP", "Accer"]
override func viewDidLoad() {
super.viewDidLoad()
// Refresh control add in tableview.
refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged)
self.refreshtable.addSubview(refreshControl)
self.refreshtable.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
@objc func refresh(_ sender: Any) {
// Call webservice here after reload tableview.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as UITableViewCell!
cell.textLabel?.text = self.data[indexPath.row]
return cell
}
}
Comments
Post a Comment
Thank You.