UITableView grouped之调整任意header、footer首尾高度

来源:互联网 发布:centoa安装java 7u80 编辑:程序博客网 时间:2024/05/17 22:03

实现思路:用.plain格式的tableView,自定义分割高度,避开了一头雾水的 .grouped

class ELTableControllerGrouped: UIViewController, UITableViewDataSource, UITableViewDelegate {    var table: UITableView!    var sectionCount = 5    var heightForFooter: CGFloat = 18    var heightForHeader: CGFloat = 0    override func viewDidLoad() {        super.viewDidLoad()        table = UITableView(frame: view.bounds, style: .plain)        table.delegate = self        table.dataSource = self        table.register(UITableViewCell.self, forCellReuseIdentifier: "c")        table.register(UITableViewHeaderFooterView.self, forHeaderFooterViewReuseIdentifier: "v")        view.addSubview(table)        table.backgroundColor = UIColor.groupTableViewBackground    }    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {        let cell = tableView.dequeueReusableCell(withIdentifier: "c")        cell?.textLabel?.text = "dcas"        return cell!    }    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {        tableView.deselectRow(at: indexPath, animated: true)    }    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {        return section == sectionCount-1 ? 0 : heightForFooter    }    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {        let v1 = tableView.dequeueReusableHeaderFooterView(withIdentifier: "v")!        v1.contentView.backgroundColor = UIColor.groupTableViewBackground        return section == sectionCount-1 ? nil : v1    }    func numberOfSections(in tableView: UITableView) -> Int {        return sectionCount    }    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {        return 4    }}
原创粉丝点击