25

I have a UITableView with a footer, filled with a tabBar in a custom view, done using the following code:

- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section {
    //differ between your sections or if you
    //have only on section return a static value
    return 49;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    if(footerView == nil) {
        //allocate the view if it doesn't exist yet
        footerView  = [[UIView alloc] init];
        [footerView addSubview:self.tabBarView];
    }

    //return the view for the footer
    return footerView;
}

Which is working lovely, apart from when the table has less rows than are needed to fill the screen, this causes the footer to move up the screen, as the table no longer creates empty rows, due to having a footer.

So, does anyone know of a way to either lock the custom footer to the bottom of the screen, or, to make the tableView create empty rows as it used to do?

Thanks!

Gareth

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gareth Jeanne
  • 1,410
  • 2
  • 19
  • 35

2 Answers2

4

Unfortunately I don't think there is an easy way to do this, other than some view hierarchy trickery. When the contentSize of your UITableView is less than the frame size, you assign the footer view to self.view and position manually. When the contentSize of your UITableView is greater than the frame size, you use viewForFooterInSection. Let me know if this isn't clear or if you'd like to see some sample code on how to do this.

Dany Joumaa
  • 2,030
  • 6
  • 30
  • 45
1

I have the same problem for uitableview controller, I solved this by adding view in the window and remove this object in viewWillDisappear.

My Solution link

Community
  • 1
  • 1
g212gs
  • 863
  • 10
  • 26