in iOS 8 UITableView heightForHeaderInSection is not optional

会有一股神秘感。 提交于 2020-01-03 10:41:13

问题


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


回答1:


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;
}



回答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.



来源:https://stackoverflow.com/questions/25660329/in-ios-8-uitableview-heightforheaderinsection-is-not-optional

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!