Skip to content

Instantly share code, notes, and snippets.

@riccjohn
Last active December 5, 2019 15:16
Show Gist options
  • Save riccjohn/71c43e481ae77cdbbf68e7a65d0af3a2 to your computer and use it in GitHub Desktop.
Save riccjohn/71c43e481ae77cdbbf68e7a65d0af3a2 to your computer and use it in GitHub Desktop.
RobotListViewController - Inheritance
public class RobotListViewController: UITableViewController {
@IBOutlet public var robotTableView: UITableView!
let tableView:UITableView = UITableView()
let robots: [Robot] = [
Robot(id: 1, name: "Woofbot"),
Robot(id: 2, name: "Barkbot")
]
override public func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.text = robots[indexPath.row].name
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return robots.count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment