Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created May 6, 2020 12:10
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/465bd22dbbee665db34a722880e56b49 to your computer and use it in GitHub Desktop.
Save stevencurtis/465bd22dbbee665db34a722880e56b49 to your computer and use it in GitHub Desktop.
ViewControllerAnimals
class ViewController: UIViewController {
var data = ["Dogs", "Cats", "Celebrities", "Ducks", "Galapagos Giant Tortoise", "Parastratiosphecomyia sphecomyioides: Near Soldier Wasp-Fly", "Frog"]
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.animalLabel.text = data[indexPath.row]
cell.selectionStyle = .none
return cell
}
}
extension ViewController: UITableViewDelegate { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment