Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a footer to UITableView at the bottom

I am doing a slide menu using a UITableView and I have 2 options on the menu and I want to put a button at the bottom like in this image:

enter image description here

I try to do that add a tableFooterView like that.

UIView *footerView  = [[UIView alloc] initWithFrame:CGRectMake(0, 500, 320, 70)];
footerView.backgroundColor = [UIColor blackColor];
self.tableView.tableFooterView = footerView;

However, the view appears just after the second cell, but I want it at the bottom.

Thanks for help.

like image 412
Greg Avatar asked Feb 18 '13 00:02

Greg


People also ask

How do you add a footer in tableView?

To create a basic header or footer with a text label, override the tableView(_:titleForHeaderInSection:) or tableView(_:titleForFooterInSection:) method of your table's data source object. The table view creates a standard header or footer for you and inserts it into the table at the specified location.

What is Tablefooterview?

The view that displays below the table's content.


1 Answers

No you shouldn't add any empty cells, that's just hacky. If you really need the button to be at the bottom, you should use layoutSubviews to control the frame of the tableView and the footerView.

- (void)layoutSubviews
{
   [super layoutSubviews];
   self.tableView.frame = // top 80% of the screen
   self.footerView.frame = // bottom 20% of the screen
}
like image 98
bpercevic Avatar answered Oct 02 '22 23:10

bpercevic