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;
}
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?
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.
using the following code :
self.tableView.tableFooterView?.hidden = false
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];
}`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With