Remove footer of tableview

I’m implementing a tableview, I was trying to hide footers in section using:

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude

}

func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) → String? {
return nil
}
but it didn’t work for me.


However, if return some string to titleforfooterInSection, like this:

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat.leastNormalMagnitude

}

func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) → String? {
return “?”
}
the footer disappears, everything works smoothly.

I’m just wondering someone could explains this a bit? Thanks!

And, why the last footer is bigger than other footers in sections? I assume tableview has its own footer other than footers in section

Hi @jiang ! If you are only trying to hide footers in the tableview you can also try, self.tableView.tableFooterView?.hidden = false in the viewDidLoad. Although it appears that you’ve found a solution to hiding the footer in your case. In regards to using CGFloat.leastNormalMagnitude, my guess is that it was returning a negative value. Happy coding!

Gina

Hi,

Thanks for your answer, I have tried setting hiding footer, but it seems that it works but for the last footer which is bigger than the footers between sections.

This topic was automatically closed after 166 days. New replies are no longer allowed.