table 视图的公共委托

Common delegate for table views

我有一些在许多 table 视图中重复出现的方法。是否可以在单独的公共 class 中移动此实现?如果是那么如何?请码。有什么办法可以避免这种重复?

这种实现的一个例子是在我最后重复的最后一个单元格下方的页脚中给出 space。

extension MessagesViewController: UITableViewDelegate {

    // Set space below footer
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 40))
        footerView.backgroundColor = .clear
        return footerView
    }

    // Set height for footer
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 40
    }
}

我在父 class 中实现了通用委托,并从 class 继承了 VC。成功了。