【UITableView】坑一:tableView:heightForHeaderInSection:方法不执行

在iOS11之后,当使用UITableView时,`tableView:heightForHeaderInSection:`和`tableView:heightForFooterInSection:`代理方法可能不会自动调用。为了解决这个问题,需要显式设置tableView的`sectionHeaderHeight`和`sectionFooterHeight`属性为非零值,例如设置为0.01,这样这两个方法才会被正确响应。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iOS11后

tableView:heightForHeaderInSection:代理方法方法不执行


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

return 10;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

   return 10;

}

设置下面两个属性值后,上面两个方法才能响应


_tableView.sectionHeaderHeight = 0.01;

_tableView.sectionFooterHeight = 0.01;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值