美文网首页
TableView SectionHeaderView和Sect

TableView SectionHeaderView和Sect

作者: 崠崠 | 来源:发表于2018-07-20 15:48 被阅读0次
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

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

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;

iOS11之前的版本,在heightForFooterInSection和heightForHeaderInSection设置view的高度为0的时候,系统不会设置为0,会自动设置为默认高度。如:设置heightForFooterInSection为0:


对比.png

为了兼容之前的版本,正确的设置方法还是设置高度为:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001f;
}
//iOS 11 设置头部高度 也必须实现这两个协议方法 设置一个新的view或者为nil
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}

相关文章

网友评论

      本文标题:TableView SectionHeaderView和Sect

      本文链接:https://www.haomeiwen.com/subject/clhqmftx.html