102

I'm fairly new to iOS development.

I want to add a footer to the table view in a UITableViewController. I've made the view I want to use as the footer graphically in Storyboard, however I can't work out how to hook it up as the footer to my table view.

I can add a footer programmatically in UITableViewController's viewDidLoad method by assigning self.tableView.tableFooterView. But I've created my footer view in Storyboard, what is the best practice way of adding it as the footer to my table view?

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Jon Cox
  • 10,622
  • 22
  • 78
  • 123

3 Answers3

201

You can just drag a view to the bottom area of the tableView. You'll see in the hierarchy that it will be a subview of the tableview. You can then drag subviews such as labels and buttons there, adjust the height, etc.

dbrajkovic
  • 3,693
  • 1
  • 17
  • 14
  • 113
    Note that you can only do this if you have more than 0 prototype cells specified. Otherwise, the dragged-in view always becomes the header. To fix this, change the number of prototype cells to 1, drag in the view underneath the one prototype cell, then change the number of prototype cells back to 0. – John Brewer Sep 08 '12 at 02:02
  • 1
    Thanks for the answer. It saved me a day. I was working on adding an extra cell with Button on it, and was trapped with CoreData failure when updating the tableView. I didn't know that it could be done like this. Such an easy and clean solution for me. – John Nov 07 '12 at 11:41
  • 2
    I've done exactly as described - added a view to footer, created the class for my footer view but when I try to connect outlets it fails! It just do not see the class where to add outlets (manual selection makes no use) – Stas Apr 04 '13 at 12:35
  • 8
    If you're having trouble getting to dragged in view to be the footer view, add a header view and then try to add another view the same way you added the header view and it will set itself to the footer, then can delete the header. – Chris Wagner Oct 09 '13 at 23:27
  • Is this answer working today with Xcode 6 (2015)? My UITableView has one prototype cell and if I drag a button to the UITableView, it is hosted in the prototype cell instead of creating a footer view. If I drag the button to the `Document Outline > Table View` it doesn't work. The button is hosted at the same level of "First responder" or "Exit" – sports May 25 '15 at 18:36
  • 1
    I just dropped a view on UITableView. It is not showing at bottom. When I move that above the cell, it shows in the start of the Table. While below it is not showing at all. Any Reason why @JohnBrewer – AsifHabib Mar 15 '16 at 15:16
  • This is still working on XCode 7.3.1. Just make sure after you drag the view in after setting a prototype cell that you re-drag the view so that it's definitely visually below the cell and then turn off the cell. Once the cell is turned off, the view is the only child view of the tableview and even though it doesn't look like it, it definitely is the footer. – micnguyen Nov 17 '16 at 01:29
  • Also make sure you have given trailing, leading, top bottom constraint to table view – Ali Nov 10 '17 at 19:29
  • @JohnBrewer You may add your comment as answer. I think many people search this question, because they have a problem with dynamic cells and footer in the storyboard. It helped me. Thank you very much! – Kiryl Bielašeŭski Nov 18 '17 at 19:46
  • Alongside to that @JohnBrewer said, if there is no cell and you add a subview the first one will be the header and the second one the footer, so if you need just a footer add a zero height header and then the footer or manually edited the storyboard. – BuguiBu Jul 24 '19 at 13:42
  • 1
    This appeared to work for me but the table view doesn't appear to be letting me scroll down to see all of my footer. For example, I created just a blank 500 height view but I can only scroll down to see about half of it. If I debug the view hierarchy in xcode, the view has the correct height of 500 but, as I said, only about half of it is visible. Anyone know why that would be? – Tim Schmidt Aug 07 '19 at 14:53
11

Very simple!. dbrajkovic solution but in a graphical way. Just add a view to the table view.That's all!. enter image description here

In that example the footer view (Disclaimer View) has two labels ( Llb Disclaimer Title and Lbl Disclaimer Content).

Wilson
  • 9,006
  • 3
  • 42
  • 46
5

The above answer worked for me with one twist. I found I couldn't add a footer if the cells filled up the entire height of the table view. Removing a couple of cells allowed me to add the footer, after which I was able to add the cells back.

timschmitz
  • 592
  • 4
  • 10