Swift - UITableView 的自定义区头和自定义区尾 约束报错问题

1. UITableview先走 预设高度的代理

预设头部高度 :

func tableview(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat{

  return 40

}

预设尾部高度:

func tableview(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {

  return 33

}

然后再走 初始化方法 :

    override init(reuseIdentifier: String?) {

        super.init(reuseIdentifier: reuseIdentifier)

        configUI()

    }

所以 设置UITableview 自定义头部 和尾部 一定要先实现  预设高度的代理, 预估一个高度, 不然约束报错 

真正的区尾高度 和区头高度 直接让UITableview 自己去获取就行

    /// 分区头部view的高度

    func tableView

(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat{

        return UITableView.automaticDimension

    }

    /// 分区尾部view的高度

    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat{

        return UITableView.automaticDimension

    }

猜你喜欢

转载自www.cnblogs.com/qingzZ/p/11933979.html