Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView, make footer stay at bottom of screen? [duplicate]

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

like image 230
Gareth Jeanne Avatar asked Aug 04 '13 21:08

Gareth Jeanne


People also ask

How can I make the Footerview always stay at the bottom in Uitableviewcontroller?

If you need to make the footer view fixed at the bottom then you can not use a TableViewController . You will have to use UIViewController , put your tableView as a subview. Put the footer also as another subview and its done.

What is Tablefooterview?

The view that displays below the table's content.


2 Answers

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.

like image 94
Dany Joumaa Avatar answered Sep 20 '22 15:09

Dany Joumaa


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

like image 21
g212gs Avatar answered Sep 18 '22 15:09

g212gs