0

I have a custom UITableViewCell that I am using as footer for UITableView.

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

This footer has autolayout like http://joxi.ru/DrloGbpC4Eb3vA 1 - view 1 2 - view 2 3 - view 2 height constraint (view2Height)

At init phase view2Height is 0, and for some actions I want to change this constraint constant to another value, for example - 50, and make my header changed to.

Is there any way to implement this?

Pavel Zagorskyy
  • 443
  • 1
  • 4
  • 20

4 Answers4

0

You can override heightForFooterInSection and return 0 or 50 based on the requirement and reload table section.

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

        //return value based on condition 
    }
2ank3th
  • 2,948
  • 2
  • 21
  • 35
  • I can't get access to my footer cell in this method, so I can't change constraint changing whole height won't give the result I want, because I use auto layout – Pavel Zagorskyy Mar 20 '16 at 15:22
0

This is very easy. When you say dynamic it means you need some condition to change it. For ex : Subclass two UITableviewCells and then just reload the table view.

Abhishek
  • 358
  • 3
  • 10
0

Adding to @2ank3th answer, you can get the cell/view of footer.

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.

}
Varun
  • 759
  • 6
  • 12
0
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 
{
    return UITableViewAutomaticDimension
}

func tableView(tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat
{
    return 44.0
}
Shrikant Tanwade
  • 1,391
  • 12
  • 21