73

I would like to make my UITableView Footer stop floating over my content, as is the default activity. I want my footer to be.. well.. a footer. Always the last view to be displayed at the end of my tableview. :)

Same thing with the header too actually.

Is there any easy way to disable it from floating over top of the table view as you scroll?

Thank you everyone, I couldn't find an answer elsewhere.

Alex Feinman
  • 5,393
  • 1
  • 30
  • 48
Jason
  • 2,445
  • 3
  • 17
  • 17

8 Answers8

129

Ok, it turns out that if you set the footer view via blahblahtableView.tableFooterView = someview; , the footer will not scroll with the table.

However, if you create your footer using viewForFooterInSection, it WILL follow your view around and stick on the bottom of the screen.

Not sure why I couldn't find this answer sooner. Sorry all :)

Bhumit Mehta
  • 16,278
  • 11
  • 50
  • 64
Jason
  • 2,445
  • 3
  • 17
  • 17
  • 66
    those are two different things: tableFooterView is the footer for the entire table. viewForFooterInSection is the footer for the given section – user102008 Sep 28 '11 at 02:16
  • 2
    What if I have multiple sections in a table view? – nonamelive Feb 09 '12 at 13:38
  • 19
    Actually is the inverse. For having the footer floating above the table you need to use `viewForFooterInSection`, otherwise if you would have the footer stick at the bottom and scrolling with the table you need `self.tableView.tableFooterView = footerView`. – Fred Collins Jun 16 '13 at 03:09
  • 1
    it's strange behaviour of footer: I assign small imageView and it's frame really makes some hell.:\ – gaussblurinc Aug 22 '13 at 17:19
  • 2
    What if you want to prevent the floating but you have more than one section and the footer should be shown in the first section? – mikrobi Aug 20 '15 at 13:40
  • self.tblView.tableFooterView = footerview worked for me. My footer view was scrolling with tableview. – sonali Oct 04 '19 at 07:04
38
- (id)init {
    self = [self initWithStyle:UITableViewStyleGrouped]; //Default is UITableViewStylePlain
    return self;
}
guogangj
  • 2,275
  • 3
  • 27
  • 44
33

You have 2 types of footer: one is the section footer and the other is the tableview footer.

The section footer appears below of each section. On the other side, the tableview footer appears just once at the end of the tableview.

There is no 1-click way to disable the floating of the section footer.

If you want a "footer" that always appears as the last cell of its section and does get fixed on the bottom of the tableview you need to add an extra cell to your section and always treat it as the last one of your section.

If you just have 1 section in your tableview, you could use the tableview footer to be your footer.

rsc
  • 10,348
  • 5
  • 39
  • 36
  • 2
    According to the other answers for this question, you actually can disable the floating of the section footer in "1-click" by setting the table view style to UITableView.Style.grouped, either in code or in XIB/Storyboard. – import this Jul 24 '20 at 22:29
8

If you have your cells divided into sections and are using the function:

func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?

to set your footer, then in IB you could also set the UITableView Style to Grouped is another possible solution!

megu5202
  • 151
  • 2
  • 3
  • When I use the Grouped style, the automatic heights of my rows aren't right. They all seem to try and be the same size as one another leading to a bunch of unwanted whitespace. – JCutting8 Apr 25 '22 at 16:55
3
self.YOUR_TABLE_VIEW.tableFooterView = YOUR_FOOTER_VIEW;
Ashkan Mobayen Khiabani
  • 33,575
  • 33
  • 102
  • 171
Zulqarnain Mustafa
  • 1,615
  • 2
  • 22
  • 25
0

#pragma mark -- There are two options to do so --

  1. Use UITableView delegate

    effect: Floating footer on a table view

-(CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section{
    return HEIGHT;
}
-(UIView*)tableView:(UITableView *)tableView
viewForFooterInSection:(NSInteger)section{
    return FOOTERVIEW
}
  1. Use setter of table view

    effect: Attached at the bottom of last cell

theTableView.tableFooterView = YOURFOOTERVIEW

// Do not set this delegate
// or you would get a extra blank at the bottom of the table

//  -(CGFloat)tableView:(UITableView *)tableView
//  heightForFooterInSection:(NSInteger)section{
//    return HEIGHT;
//  }
Exile3daime
  • 611
  • 6
  • 18
0

If I got the question right, you basically want to fix the footer/header in place and scroll everything else? If so you could just have the header and the footer as separate views from the tableview, that rest above the tableview in the view hierarchy, so they cover the contents of the tableview.

If you want them to bounce (when scrolling above or below the contents) with the tableview, then you need to track the tableview's method (tableview is a subclass of scrollview, so it works) - (void)scrollViewDidScroll: and calculate the new position to either the footer or the header in there.

I hope you get my answer, I have done something similar to this and it worked (I wanted the "Release to update" kind of thingy on top of the tableview)

Henri Normak
  • 4,695
  • 2
  • 23
  • 33
  • Rather the opposite... i want the footer/header to basically act as the first and last cell of the tableview in every respect :)... i'm a bit foggy on if your answer could help achieve that to be honest. – Jason Apr 21 '11 at 07:29
  • 1
    Then what's the problem? Just have them as the first and last cell, that's it. Or you could simply have them as the headerView/footerView. What am I missing or you not telling? :P – Henri Normak Apr 21 '11 at 07:32
  • Well the problem is I need them to have a specific height, different then the rest of the cells, and i don't want to take on the burden of running the cellheightforrow method (docs state in large tables there is a performance degradation) --- have them as the header/footerview? I do have them as the header/footerview using viewForFooterInSection... but it sticks to the bottom of the screen when scrolling the table ;( – Jason Apr 21 '11 at 07:35
  • 1
    Wow.. that was easy.. i just had to set Footer view instead of view for section footer... wow – Jason Apr 21 '11 at 07:39
  • Glad it worked out, that was what I was thinking by footerView/headerView, these are two properties of the tableview. – Henri Normak Apr 21 '11 at 07:52
  • It's strange that setting the view would keep it on the bottom but setting it via section footer view method makes it stick... interesting. – Jason Apr 21 '11 at 07:58
0

I was having a similar problem. I was using only a footer to indicate the number of cell in the table at the bottom of it. But it was not scrolling with the table cels as i expected (its was visible at all times on top of the table until i reach the bottom where it bounces off).

My solution to overcome this was to create 2 sections, one contains the table cells and another empty BUT with a header. This header will show the counter and will behave as i wanted (to remain at the bottom of the table at all times rather than overlaying the cells).

The recommended solution of adding a dummy cell at the bottom was not useful in my case at it would be bordered with the table wired-border and i did not want that.

Hope this helps

Abolfoooud
  • 2,663
  • 2
  • 27
  • 27