I used to have a base class that inherited from UITableViewController and defined some defaults for the delegates, as well as a viewDidLoad default. I'm now trying to change that to be a protocol extension instead, so I did the following:
protocol HeaderSectionRenderer {
func coloredHeaderViewWithText(title: String, uppercase: Bool) -> UITableViewHeaderFooterView
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
}
extension HeaderSectionRenderer where Self: UITableViewController {
func coloredHeaderViewWithText(title: String, uppercase: Bool = false) -> UITableViewHeaderFooterView {
...
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 25.0
}
}That covers those two methods with a default implementation, but now I need to have a viewDidLoad. I tried the obvious:
override func viewDidLoad() {
super.viewDidLoad()
tableView.registerClass(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "header")
}but that gives an error saying, "Method does not override any method from its superclass". I'm basically looking for a way such that any UIViewController which implements this protocol automatically registers the header/footer class.