PlayerTableViewController - Ben-Stacey/COSC345 GitHub Wiki
PlayerTableViewController
View Controller for the table
class PlayerTableViewController: UITableViewController
Inheritance
UITableViewController
Properties
players
Data that is displayed in the table
let players = [
Player(name: MainMenu.getName(), score: HomeScreen.getScore()),
Player(name: "Bruce", score: 5),
Player(name: "Bob", score: 4),
Player(name: "Brent", score: 3),
Player(name: "Keith", score: 2),
Player(name: "Rob", score: 1),
]
Methods
tableView(_:numberOfRowsInSection:)
Makes as many cells as the length of objects in players
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
Parameters
- tableView: The table
- numberOfRowsInSection: Rows in the table
Returns
- Int: number of rows in the table
tableView(_:cellForRowAt:)
Creates the view for each cell in the table by adding the text onto the label
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
Parameters
- tableView: Gets the table
- cellForRowAt: the index of the cell
Returns
- UITableViewCell: Cell
tableView(_:titleForHeaderInSection:)
The name at the top of the table
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
Parameters
- tableView: the table
- titleForHeaderInSection: header for the table
Returns
- String: name for table