Footer in TableView

Hi all,

I would like to add a footer to the “Checklist” project, in the “Checklist” scene, where you have the list of the items.

I also checked here: Footer tableview

I did it, but it does not stick to the footer of the tableView, but to the bottom part of the last cell; if there is only one cell, then the “footer” is basically at the top of the tableView.

Any ideas?

Thanks
Marco

Hi @marcogt,
A tableview does not have a footer, each section has a header and footer.
If you want a footer for a tableview, you will have to add a Label at the end of the tableview.

cheers,

Do you mean that by simpling adding a label add the end of a tableview, will be put as footer?

Hi @marcogt, maybe try adding a UIView as a footer:

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let footerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "FooterView")
    return footerView
}

And in viewDidLoad add,

tableView.register("FooterView", forHeaderFooterViewReuseIdentifier: "FooterView")

Best,
Gina

tableView.register(“FooterView”, forHeaderFooterViewReuseIdentifier: “FooterView”)

This is not working because the register function does not expect a String as first argument, but a NIB

“Cannot invoke ‘register’ with an argument list of type '(String, forHeaderFooterView)”

I succeeded like this:

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerView = UIView(frame: CGRect(x:0, y:0, width:tableView.frame.size.width, height:40))
        footerView.backgroundColor = UIColor.lightGray
        
        return footerView
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 40.0
    }

But this will put a footer at the end of the section, and not at the end of the table

Hi @marcogt,
You have two threads with the same related problem that you are trying to resolve.

It would be nice if Apple would do everything automagically, however then there would be no developers.

Specifically if you want a footer for your TableView, you will have to add an element in the storyboard that is physically just below the tableview. For simple text I had suggested a UILabel, with your other question @gdelarosa suggested you add a UIView that an host other elements like UIButtons and UILabels, etc.

There is NO API that creates a footer so you have to visually position it at the end of the tableView and write the code - It will be totally unrelated to the TableView, so if you want to hide it when you have an empty tableView, you have to do that yourself.

cheers,

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