Phan Văn Linh Phan Văn Linh - 2 years ago 713
iOS Question

UITableViewAutomaticDimension not working for footer in iOS8

I have a footer in

. The footer just only contains a
and I want adjust footer height depend on
so I have use

self.tableview.estimatedSectionFooterHeight = 140;
self.tableview.sectionFooterHeight = UITableViewAutomaticDimension;

It works well on iOS9 but not work in iOS8
enter image description here

Here is my footer view
enter image description here
has constraints:
top=5, leading/trailing=8, bottom=34, line=0, height >= 18

Here is my code for init footer

- (UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
NSArray* nibViews = [[NSBundle mainBundle] loadNibNamed:@"BaseFooterViewCell" owner:self options:nil];
BaseFooterViewCell *myFooterView = [nibViews objectAtIndex: 0];
myFooterView.contentLabel.text = @"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
return myFooterView;

How can I make it work in iOS8? Any help or suggestion would be great appreciated.

If you can not understand my problem, please check the DEMO PROJECT

In some case, my footer will more complex, it doesn't only contains one
, and also
will have different size for
. Therefore, it's really hard to calculate footer height correctly. I still want to use

Answer Source

After test, here is my results

For iOS8, UITableViewAutomaticDimension only work for section header and tableview cell and not work for section footer

BUT strangely, if my tableview use both section header and footer, the UITableViewAutomaticDimension will work for footer.

Then here is the solution

- (void)viewDidLoad {
    // I set UITableViewAutomaticDimension for both footer and header
    self.tableview.estimatedSectionHeaderHeight = 0; // it should be 0 because header is empty
    self.tableview.sectionHeaderHeight = UITableViewAutomaticDimension;

    self.tableview.estimatedSectionFooterHeight = 140;
    self.tableview.sectionFooterHeight = UITableViewAutomaticDimension;
// I return empty view for header
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

For iOS9 and above, UITableViewAutomaticDimension work correctly

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download