TableHeaderViewWithAutoLayout icon indicating copy to clipboard operation
TableHeaderViewWithAutoLayout copied to clipboard

What about Footer View?

Open AbrahamEP opened this issue 7 years ago • 1 comments

I used the same code for table footer view and is not working. The View is setting at the top of the table view like it was a header view.

This is my code:

  `let containerView = UIView()
    containerView.translatesAutoresizingMaskIntoConstraints = false
    
    self.totalLabelFooter = UILabel()
    self.totalLabelFooter.text = "Total: $790"
    self.totalLabelFooter.textAlignment = .right
    self.totalLabelFooter.translatesAutoresizingMaskIntoConstraints = false
    
    containerView.addSubview(self.totalLabelFooter)
    
    self.totalLabelFooter.topAnchor.constraint(equalTo: containerView.topAnchor).isActive = true
    self.totalLabelFooter.bottomAnchor.constraint(equalTo: containerView.bottomAnchor).isActive = true
    self.totalLabelFooter.leftAnchor.constraint(equalTo: containerView.leftAnchor).isActive = true
    self.totalLabelFooter.rightAnchor.constraint(equalTo: containerView.rightAnchor).isActive = true
    
    self.tableView.tableFooterView = containerView
    
    // 3.
    containerView.centerXAnchor.constraint(equalTo: self.tableView.centerXAnchor).isActive = true
    containerView.widthAnchor.constraint(equalTo: self.tableView.widthAnchor, multiplier: 0.8).isActive = true
    containerView.bottomAnchor.constraint(equalTo: self.tableView.bottomAnchor).isActive = true
    
    self.tableView.tableFooterView?.layoutIfNeeded()
    self.tableView.tableFooterView = self.tableView.tableFooterView`

AbrahamEP avatar May 23 '18 15:05 AbrahamEP

HI @AbrahamEP , I was facing the same issue not working for table footer View. I find the work around thats works for me. drag the footer view(footerView) from table View . set it as view to footer for last section (here section 1 is my last section). set footer section height dynamically from storyboard..

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { return section == 1 ? self.footerView : nil }

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return section == 0 ?  0 :  UITableView.automaticDimension
   }

a) Screenshot 2021-06-03 at 1 21 30 AM

pawanline avatar Jun 02 '21 19:06 pawanline