Created
May 4, 2020 05:56
-
-
Save akshitzaveri/3951b1efe56267f490dc45140c50667b 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
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