• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 更改 HeaderInSection 的 UITableView 的高度?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 15:20:22 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我的 UITableView 的样式很普通,我想更改 HeaderInSection 的高度,但它仍然是默认高度 22.0。

- (CGFloat)tableViewUITableView *)tableView heightForHeaderInSectionNSInteger)section
{
    if (tableView.tag == tableOrdersTag)
    {
        return 35;
    }
    else
    {
        return 0;
    }
}

- (UIView *)tableViewUITableView *)tableView viewForHeaderInSectionNSInteger)section
{
    if (tableView.tag == tableOrdersTag)
    {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frameWidth, 35)];

        view.backgroundColor = COMMON_BACKGROUND_COLOR;

        DDLogVerbose(@"=========tableView  %f", tableView.sectionHeaderHeight);

        return view;
    }
    else
    {
        return nil;
    }
}



Best Answer-推荐答案


你的 NSLog 的位置

        DDLogVerbose(@"=========tableView  %f", tableView.sectionHeaderHeight);

可能会导致问题。应该在返回方法之前:

        return view;

将数字 35 改为 100,你会发现它工作正常。

因为方法

tableView:viewForHeaderInSection 

落后于

tableView:heightForHeaderInSection.

当我创建一个没有 xib 或 Storyboard 的 TaleViewController 时:

- (NSInteger)numberOfSectionsInTableViewUITableView *)tableView {
return 1;
}
- (CGFloat)tableViewUITableView *)tableView heightForHeaderInSectionNSInteger)section
{
    NSLog(@"heightForHeaderInSection");
        return 100;
}

- (UIView *)tableViewUITableView *)tableView viewForHeaderInSectionNSInteger)section
{

        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 100)];

        view.backgroundColor = [UIColor redColor];
        NSLog(@"=========tableView  %f", tableView.sectionHeaderHeight);
        return view;
}

它会像这样打印:

 2015-05-21 18:25:30.525 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.526 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.526 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.526 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.535 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.535 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.549 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.549 UITableViewHeaderDemo[24727:2350493] heightForHeaderInSection
 2015-05-21 18:25:30.550 UITableViewHeaderDemo[24727:2350493] =========tableView  -1.000000

但是 It works fine

关于ios - 更改 HeaderInSection 的 UITableView 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30370257/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap