How to add touch events to a UITableViewFooter (or header)

Table View headers or footers can’t be tapped. Sometimes however that’s exactly what we want to do.

In this example we’ll add a new UIView to out table view and add it to the table’s footer. Inside this view we’ll have a custom button which we’ll create with an image. We’ll also have a method that is called when the user presses the button:

The result is a row at the bottom of the table view which stays in place even if the table is scrolled – ideal of anything users should see at all times.

You can do the same for table view headers, just add the code to the “headerInSeaction” variants of the methods above.

Example of a tappable footer image/button
Example of a tappable footer image/button

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

3 thoughts on “How to add touch events to a UITableViewFooter (or header)

    1. Hi Joan, that’s not correct: the viewForFooterInSection method is called exactly once, not multiple times – hence the button is created only once. Try it out with a simple log message.

      Alternatively, you can create reference to the button (or in fact the footer view) with a custom initialiser and simply call that in viewForFooterInSection. Or you can tag your view and ask if it exists before creating it again – just in case you’re worried.

      And perhaps next time, rather than simply expressing a dislike in an article, offer some advice to us all on how to make it better.

Leave a Reply to Jay Versluis Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.