Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created May 6, 2020 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/cb9d62ecf2b487e36bb950226209267d to your computer and use it in GitHub Desktop.
Save stevencurtis/cb9d62ecf2b487e36bb950226209267d to your computer and use it in GitHub Desktop.
ViewControllerCell
class ViewController: UIViewController {
var data = ["Dave Smith", "Ahmed Khan", "Lakshmi Manchu" ,"Tom Rogers"]
var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView = UITableView(frame: self.view.frame)
tableView.delegate = self
tableView.dataSource = self
let nib = UINib(nibName: "CustomTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "cell")
tableView.estimatedRowHeight = 44
self.view = tableView
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell
cell.nameLabel.text = data[indexPath.row]
return cell
}
}
extension ViewController: UITableViewDelegate {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment