Last active
February 16, 2017 13:31
-
-
Save nahive/20e27b4a3f0fb290678eba310ce2089b to your computer and use it in GitHub Desktop.
Example of handling sections in UITableView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Section: Int { | |
case robots = 0 | |
case cats | |
case dogs | |
case humans | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
switch Section(rawValue: section) { | |
case .robots?: // return rows count | |
case .cats?: // return rows count | |
case .dogs?: // return rows count | |
case .humans?: // return rows count | |
default: fatalError() | |
} | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
switch Section(rawValue: indexPath.section) { | |
case .robots?: // dequeue cell | |
case .cats?: // dequeue cell | |
case .dogs?: // dequeue cell | |
case .humans?: // dequeue cell | |
default: fatalError() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment