Skip to content

Instantly share code, notes, and snippets.

@RNHTTR
Created September 25, 2017 02:30
Show Gist options
  • Save RNHTTR/e702d9a07ba2b02f6ca669a295ac8c30 to your computer and use it in GitHub Desktop.
Save RNHTTR/e702d9a07ba2b02f6ca669a295ac8c30 to your computer and use it in GitHub Desktop.
Determine the number of rows in each of a UITableView's sections
// Use tableView(_:numberOfRowsInSection:) to determine the number of rows each section of a UITableView should display.
// This example exhibits how this app makes use of this method.
// Create some sort of data source. This is often an array or, in this case, a dictionary.
var dataSource: [String: String] {
return ["cellForRowAt: indexPath": "Update cell information based on the data source\nReturns a UITableViewCell.",
"numberOfRowsInSection: Int": "Determine the number of rows needed for each section of the tableView\nReturns an Int",
"titleForHeaderInSection: Int": "Set the title for a particular section of your tableView\nReturns a String"]
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Use the count of the data source to determine how many rows will be in each section. In this case, there's only one
// section, so this will give the number of cells for the entire table view.
return dataSource.count
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment