Hiding a UITableView Footer

I cannot hide the UITableView footer (i.e. set its height to 0 and animate the transition).

I tried to wrap tableView.tableViewFooter.height = 0 (and tableView.tableViewFooter = nil ) between [tableView beginUpdates] and [tableView endUpdates] , but it does not work.

The implementation of 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 table footer and a section footer? I created my own by clicking a button under my desk in my storyboard.

Any ideas to make this simple?

+8
ios objective-c cocoa-touch uikit uitableview
source share
6 answers

Ok, this is 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 from appearing in the table view.

I don't need an animation block, but other people can.

 [UIView animateWithDuration:0.5 animations:^{ }]; 

In addition, I had to maintain a strong link to my IBOutlet tableFooterButton. This was part of why my initial attempt to solve the problem failed. I'm not sure if having a good link to IBOutlet is a good practice. You can leave a comment about this.

+9
source share

using the following code:

 self.tableView.tableFooterView?.hidden = false 
+6
source share

That 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]; }` 
+2
source share

use the following methods:

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.0f; } -(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section { return [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; }` 
+1
source share

So, after all, this is the simplest solution I can give you. So, as you can see, I just put .m (for simplicity).

There is a difference between the table footer and the section footer. What you are looking for is a section footer.

I also added an animation block to add and remove.

 #import "ViewController.h" @interface ViewController () @end @implementation ViewController UIButton *_footerButton; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self createAndAddFooterButton]; } -(void) buttonPressed:(id)button { [UIView animateWithDuration:2 animations:^{ self.tableView.tableFooterView = nil; }]; } - (void)createAndAddFooterButton { // here you create the button _footerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [_footerButton setTitle:@"Button Title" forState:UIControlStateNormal]; [_footerButton sizeToFit]; [_footerButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [UIView animateWithDuration:2 animations:^{ self.tableView.tableFooterView = _footerButton; }]; } @end 
0
source share

My problem was that the clear line was the footer, which I could only define as 1 pixel, not 0 (since I don't want to have a footer). The only way I could fix this was to provide the view in viewForFooterInSection and set the background color to the same as the title so that you would not notice it visually, and when I animate new lines, they do not appear at the top of the title, where there was a clear line (footer).

  override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { let blankView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 1)) blankView.backgroundColor = {Same colour as Header} return blankView 
0
source share

All Articles