Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding UITableView footer

I am unable to hide my UITableView footer (i.e. setting it's height to 0 and animating the transition).

I tried to wrap tableView.tableViewFooter.height = 0 (and tableView.tableViewFooter = nil) between [tableView beginUpdates] and [tableView endUpdates] but it doesn't work.

Implementing the method below creates another footer.

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 50;
}

enter image description here

Is there a difference between a tableview footer and a section footer? I created mine by dropping a button under my tableview in my storyboard.

Any ideas to do this simply?

like image 894
user3250560 Avatar asked Mar 05 '14 19:03

user3250560


3 Answers

Ok here's how I solved this problem.

- (void)refreshTableFooterButton
{
    if (should be visible) {
        self.tableView.tableFooterView = self.tableFooterButton;
    } else {
        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
}

I used [[UIView alloc] initWithFrame:CGRectZero instead of nil to prevent unwanted empty cells to appear in the tableview.

I didn't need an animation block, but other people might.

[UIView animateWithDuration:0.5 animations:^{

}];

Also, i had to keep a strong reference to my tableFooterButton IBOutlet. That was part of why my initial attempt at solving the problem failed. I'm not sure if having a strong reference to an IBOutlet is good practice though. Feel free to leave a comment about that.

like image 51
user3250560 Avatar answered Sep 29 '22 12:09

user3250560


using the following code :

self.tableView.tableFooterView?.hidden = false
like image 21
machine Avatar answered Sep 29 '22 12:09

machine


This should do the trick. There are other alternatives such as this answer here.

tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;

-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1.0;


-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
    return 1.0;
}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}

-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
    return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}`
like image 40
ridacl Avatar answered Sep 29 '22 13:09

ridacl