【问题标题】:UITableView section header height for non-grouped table非分组表的 UITableView 部分标题高度
【发布时间】:2010-11-17 04:13:02
【问题描述】:

您好!我知道 UITableView sectionHeaderHeight 仅用于分组表,但无论如何我都会问(以防有一些不明显的方法)......

有没有办法更改 NON 分组表的节标题高度(以及字体/大小)?

希望“是”或至少是“可能”……但担心可能是“否”。伙计们,努力吧。

【问题讨论】:

    标签: uitableview header height iphone-sdk-3.0


    【解决方案1】:

    是的。

    使用这个委托方法:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
        return 44;
    }
    

    当然,根据需要进行更改。当然还有一个用于页脚的:

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
        return 44;
    }
    

    【讨论】:

    • 谢谢!当然,我在 iPhone OS 3.0 中尝试过,但似乎没有用。它只会保持相同的高度。然而,它在 3.1 中工作得很好,所以我怀疑我们把它归结为“错误修复”或“试点错误”。 (总是很高兴承认是后者,但我只是不确定为什么如果这不是一个错误修复,它就不能更早地工作。即使我有 sectionHeaderHeight 在玩,它会被 tableView:heightForHeaderInSection: 覆盖。嗯 ...)
    【解决方案2】:

    至少从 iOS 9(经过测试)UITableView.sectionHeaderHeight 也适用于普通表格视图(非分组)!

    您将获得默认标题高度(通常为 22.0)。

    当然,表视图委托可能在其 tableView:heightForHeaderInSection: 方法中自定义了此默认值。

    下面的代码 sn-p 给出了定义的节标题的高度:

    CGFloat headerHeight = self.tableView.sectionHeaderHeight;
    if ([self.tableView.delegate respondsToSelector:@selector(tableView:heightForHeaderInSection:)]) {
        // possibly custom header height
        headerHeight = [self.tableView.delegate tableView:self.tableView heightForHeaderInSection:indexPathForCell.section];
    }
    

    【讨论】:

      猜你喜欢
      • 2016-07-05
      • 2013-07-16
      • 2013-08-05
      • 2014-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多