Last active
January 29, 2020 04:39
-
-
Save mimthath4/ae35f67f4090d9f80f9bec8cff7f66d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class MITableViewController: UITableViewController { | |
var sections: [SectionItem] = [] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
registerCells() | |
} | |
func registerCells() { | |
assertionFailure("override this function to register cells for the table view") | |
} | |
} | |
extension MITableViewController { | |
override func numberOfSections(in tableView: UITableView) -> Int { | |
return sections.count | |
} | |
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | |
return sections[section].header | |
} | |
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return sections[section].items.count | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
return sections[indexPath.section].items[indexPath.row].getCell(at: indexPath, of: tableView) | |
} | |
} | |
extension MITableViewController { | |
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | |
return sections[indexPath.section].items[indexPath.row].height | |
} | |
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
tableView.deselectRow(at: indexPath, animated: true) | |
sections[indexPath.section].items[indexPath.row].didSelect(at: indexPath) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment