Skip to content

Instantly share code, notes, and snippets.

@andrewjmeier
Last active May 31, 2017 17:46
Show Gist options
  • Save andrewjmeier/824cf256804186cd50039570bdf2f2ea to your computer and use it in GitHub Desktop.
Save andrewjmeier/824cf256804186cd50039570bdf2f2ea to your computer and use it in GitHub Desktop.
UITableViewDelegate/DataSource template
// Not all methods in the protocols, but the ones that I find useful the most. (commented out methods are optional.)
// MARK: UITableViewDelegate
extension MyViewController: UITableViewDelegate {
// MARK: Configuring a Table
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: "cell")!
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
// func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
// func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
}
// MARK: UITableViewDataSource
extension MyViewController: UITableViewDataSource {
// MARK: Configuring Rows for a Table
// func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
// func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
// MARK: Managing Selections
// func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath?
// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
// func tableView(_ tableView: UITableView, willDeselectRowAt indexPath: IndexPath) -> IndexPath?
// func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath)
// MARK: Modifying the Header and Footer of Sections
// func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
// func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
// func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
// return CGFloat.leastNonzeroMagnitude
// }
// func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// return CGFloat.leastNonzeroMagnitude
// }
// MARK: Managing Table View Highlighting
// func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool
// func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment