UITableview doesn't populate section header for 0th section in a certain configuration

Originator:avner
Number:rdar://29925225 Date Originated:9/1/17
Status:Open Resolved:NO
Product:UIKit Product Version:
Classification:UI Bug Reproducible:Always
 
Area:
UIKit

Summary:
When the UITableViewDelegate optional methods are implemented, in a certain configuration the section header for the 0th section will not be populated and the delegate method is not called

Reproduced always

Steps to Reproduce:
I've removed computation logic for clarity and only left the final flow configuration leading to the bug.

Notice that when - tableView estimatedHeightForHeaderInSection:section
returns "0", the 0th section won't have a title. 

If you return "10" , the 0th section will have a header



#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  UITableView *tv = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
  tv.dataSource = (id <UITableViewDataSource>)self;
  tv.delegate = (id <UITableViewDelegate>)self;
  [tv registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
  [self.view addSubview:tv];
  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    CGFloat f = [tv sectionHeaderHeight];
    NSLog(@"%@",@(f).description);
  });
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  return 10;
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  return [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
}

- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
  return @(section).description;
}

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

//*******

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

// Use the estimatedHeight methods to quickly calcuate guessed values which will allow for fast load times of the table.
// If these methods are implemented, the above -tableView:heightForXXX calls will be deferred until views are ready to be displayed, so more expensive logic can be placed there.
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
  return UITableViewAutomaticDimension;
}

////*******
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
  return 0;
}
//- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForFooterInSection:(NSInteger)section
//{
//  return 0;
//}

// Section header & footer information. Views are preferred over title should you decide to provide both

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section   // custom view for header. will be adjusted to default or specified header height
{
  return nil;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section   // custom view for footer. will be adjusted to default or specified footer height

{
  return nil;
}
@end


Expected Results:
0th section should have a header title

Actual Results:
0th section doesn't have a title

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!