在iOS 8中,UITableView heightForHeaderInSection不是可选的 [英] in iOS 8 UITableView heightForHeaderInSection is not optional

查看:96
本文介绍了在iOS 8中,UITableView heightForHeaderInSection不是可选的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚注意到在iOS 8中,以编程方式定义的tableview必须定义 heightForHeaderInSection 以及 viewForHeaderInSection ,否则默认高度将为0且部分标题不会出现。
虽然在iOS 7中并且在部分标题下出现,即使未定义 heightForHeaderInSection 也是如此。

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.

我想知道是否有人注意到了同样的行为,因为
中没有提及 iOS 8 UITableView类引用

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

推荐答案

我可以复制此问题,并可以确认修复。我的标题视图根本没有显示出来。实现以下代码修复它(其中20 px是所需的标题高度)。

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

这篇关于在iOS 8中,UITableView heightForHeaderInSection不是可选的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆