Skip to content

Instantly share code, notes, and snippets.

@akshitzaveri
Created May 4, 2020 05:56
Show Gist options
  • Save akshitzaveri/3951b1efe56267f490dc45140c50667b to your computer and use it in GitHub Desktop.
Save akshitzaveri/3951b1efe56267f490dc45140c50667b to your computer and use it in GitHub Desktop.
import UIKit
final class TableViewAdapter: NSObject, UITableViewDataSource {
let tableView: UITableView
init(tableView: UITableView) {
self.tableView = tableView
super.init()
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.tableView.dataSource = self
self.tableView.delegate = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell") else { fatalError() }
cell.textLabel?.text = "Row \(indexPath.item + 1)"
return cell
}
}
extension TableViewAdapter: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("Selected row \(indexPath.item + 1)")
tableView.deselectRow(at: indexPath, animated: true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment