6

I've just noticed that in iOS 8, a tableview which is defined programmatically must define heightForHeaderInSection in addition of viewForHeaderInSection, otherwise the default height will be 0 and the sections headers won't appear. While in iOS 7 and under the sections header where appearing even if heightForHeaderInSection is not defined.

I wonder if somebody noticed the same behavior because it's not mentioned in the iOS 8 UITableView class reference

Omaty
  • 425
  • 5
  • 14
  • This isn't really a question. And I'm pretty sure that's the way it's always been, unless you set the table views's sectionHeaderHeight property. – Kevin Sep 04 '14 at 08:13
  • Indeed you need to override heightForHeaderInSection, heightForFooterInSection and heightForRowInSection. – idmean Sep 04 '14 at 08:18
  • 2
    @Kevin No it was not always the same. I've noticed the difference because I've just tested my app under iOS 8 with xcode 6 beta 7. Before that I had a tableview with sections headers but under iOS 8 the cells where the same but the sections headers disappeared. I still can test the two behaviors because I'm using both devices under iOS 7 and 8 beta. – Omaty Sep 04 '14 at 08:20
  • 1
    +1, thanks your question helps me to solve my quesiton :D , http://stackoverflow.com/questions/25647059/header-view-is-not-display-after-searchios8-beta5-xcode6 – Jageen Sep 05 '14 at 04:48

2 Answers2

4

I can duplicate this issue, and can confirm the fix. My header views were not showing up at all. Implementing the following code fixed it (where 20 px is the desired header height).

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  return 20;
}
Vette
  • 511
  • 5
  • 10
2

I experienced similar behavior: without the implementation of TableView: heightForHeaderInSection: some, not all, of the headers were rendered in kind of strike-through font. Or rather, a single horizontal line was rendered crossing the header. (Sorry no image, reputation catch-22.) (Both iPad and iPhone have same behavior)

Implementation of the above mentioned method resolved the issue.

Olaf Donk
  • 21
  • 3