Skip to content

Instantly share code, notes, and snippets.

@RNHTTR
Created September 25, 2017 02:44
Show Gist options
  • Save RNHTTR/23742f370b26c0181a56f552b8575020 to your computer and use it in GitHub Desktop.
Save RNHTTR/23742f370b26c0181a56f552b8575020 to your computer and use it in GitHub Desktop.
Determine the title for each section in a UITableView.
// Use tableView(_:titleForHeaderInSection:) to set the title for each section in a table view.
// This example exhibits two instances of this method used in this app.
// This demonstrates the use of this method in this app's UITableViewDataSource view controller.
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return "Configuring a Table View"
default:
print("out of index")
return ""
}
}
// This demonstrates the use of this method in this app's UITableViewDelegate view controller.
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
switch section {
case 0:
return "Configuring Rows"
case 1:
return "Managing Selections"
case 2:
return "Handling Swipe Actions"
default:
print("out of index")
return ""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment