0

我有一个自定义 UITableViewCell,用作 UITableView 的页脚。

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let cell = tableView.dequeueReusableCellWithIdentifier("footerCommentCell") as! FooterCommentTableViewCell
    cell.footerIndex = section
    cell.delegate = self
    return cell
}

此页脚具有自动布局,如 http://joxi.ru/DrloGbpC4Eb3vA 1 - 视图 1 2 - 视图 2 3 - 视图 2 高度约束 ( view2Height)

在初始化阶段view2Height是 0,对于某些操作,我想将此约束常量更改为另一个值,例如 - 50,并将我的标题更改为。

有什么方法可以实现吗?

4

4 回答 4

0
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 
{
    return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat
{
    return 44.0
}
于 2016-03-23T06:14:17.103 回答
0

您可以覆盖 heightForFooterInSection 并根据要求返回 0 或 50 并重新加载表部分。

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

        //return value based on condition 
    }
于 2016-03-20T15:10:50.870 回答
0

这很容易。当你说动态时,这意味着你需要一些条件来改变它。例如:子类化两个 UITableviewCells,然后重新加载表格视图。

于 2016-03-21T09:57:13.060 回答
0

添加到@2ank3th 答案,您可以获得页脚的单元格/视图。

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    let footerView = tableView.footerViewForSection(0) as! FooterCommentTableViewCell 
// Your section number. (0 for understanding purpose)

// Then you can modify the height constraint and return the height of footer here.

}
于 2016-03-21T16:12:49.590 回答