Created
May 6, 2020 12:10
-
-
Save stevencurtis/465bd22dbbee665db34a722880e56b49 to your computer and use it in GitHub Desktop.
ViewControllerAnimals
This file contains 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
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